Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add __repr__ to Index class #1822

Merged
merged 1 commit into from
Dec 26, 2024

Conversation

waketzheng
Copy link
Contributor

Description

  1. Add __repr__ to the Index class
  2. Update type hint for the fields argument in Index __init__ to support both tuple[str, ...] and list[str] instead of only tuple[str, ...]
  3. tests/contrib/test_pydantic.py and tests/testmodels.py was auto changed by make style

Motivation and Context

Without the custom __repr__, Index class display like this:

--> python -m IPython
Python 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.30.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from tortoise.indexes import Index

In [2]: Index(fields=('id',))
Out[2]: <tortoise.indexes.Index at 0x7ff40999ed40>

After it added:

In [1]: from tortoise.indexes import Index

In [2]: Index(fields=('id',))
Out[2]: Index(fields=['id'])

In [3]: idx = Index(fields=('id', 'name'))

In [4]: f'{idx = }'
Out[4]: "idx = Index(fields=['id', 'name'])"

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 12454956827

Details

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 90.181%

Totals Coverage Status
Change from base Build 12437576482: 0.04%
Covered Lines: 6392
Relevant Lines: 6973

💛 - Coveralls

@waketzheng waketzheng merged commit 29d7e02 into tortoise:develop Dec 26, 2024
8 checks passed
@waketzheng waketzheng deleted the repr-index branch December 26, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants