-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add lots of type hints #6122
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
base: master
Are you sure you want to change the base?
add lots of type hints #6122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @amogus07, your pull request is larger than the review limit of 150000 diff characters
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
86c1c56 to
82b7a1d
Compare
|
Hey, thanks a lot for the contribution, really appreciate the effort you’ve put into this! This PR is quite large, which makes it a bit difficult to review thoroughly. Would you mind breaking it down into smaller, more focused commits or separate PRs? For instance, you could move file relocations or refactors into their own commits to make the changes easier to follow. You can take a look at the PR linked below for an example of how to structure these kinds of refactors. It also looks like this PR touches on multiple areas of the codebase. To keep things maintainable and easier to review, it’s best if each PR focuses on a single concern or goal, rather than combining several changes at once. As a side note, have you had a chance to look at #6119? It seems to address some of the same issues you’re working on here, it might be worth aligning with that effort to avoid overlap. Thanks again for your work on this! We really appreciate your recent efforts! |
82b7a1d to
c39849f
Compare
c39849f to
40b9ad5
Compare
40b9ad5 to
2ae9270
Compare
snejus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
I reviewed a couple of files but stopped at queryparse.py since I found myself confused about the motivation for these changes?
I'm struggling to find any improvements here, while I see a fair bit off issues. Please see the comments.
| process and their access comes with a performance overhead. | ||
| """ | ||
| dist = Distance() | ||
| dist: Distance = Distance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant
| self.add(key, dist) | ||
|
|
||
| def add_data_source(self, before: str | None, after: str | None) -> None: | ||
| def add_data_source(self, before: object, after: str | None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| info_length: float | None | ||
| if info_length := track_info.length: | ||
| diff = abs(item.length - info_length) - get_track_length_grace() | ||
| diff: float = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, redundant
|
|
||
| @cached_classproperty | ||
| def _queries(cls) -> dict[str, FieldQueryType]: | ||
| def _queries(cls) -> dict[str, type[Query]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these changes from FieldQuery -> Query are incorrect. Why?
|
|
||
|
|
||
| class Results(Generic[AnyModel]): | ||
| class Results(Generic[AnyModel, D]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| r"(?<!\\):" # Unescaped : | ||
| r")?" | ||
| r"(.*)", # The term itself. | ||
| r"(-|\^)?" # Negation prefixes. # noqa: ISC003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Please undo
| # Apply the regular expression and extract the components. | ||
| part = part.strip() | ||
| match = PARSE_QUERY_PART_REGEX.match(part) | ||
| match: re.Match[str] | None = PARSE_QUERY_PART_REGEX.match(part) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant
| # If there's no key (field name) specified, this is a "match anything" | ||
| # query. | ||
| out_query = model_cls.any_field_query(pattern, query_class) | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switching the order of the conditional?
Why did you replace FieldQuery in the function input and then introduce cast here?
| query_classes[k] = t.query | ||
| query_classes.update(model_cls._queries) # Non-field queries. | ||
| query_classes.update( | ||
| model_cls._queries.items() # Non-field queries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
|
|
||
| import itertools | ||
| import re | ||
| from typing import TYPE_CHECKING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any improvements in this module except for redundant types and adjustments in function input types which then force you to use cast and type: ignore.
|
Apologies for my language - I realise I sound dismissive and terse there - I am tired and about to go to sleep, so this is my fault, not your changes <3 I take that most of these type adjustments stem from you using Would you mind running Thanks again for your effort on this - I really do appreciate it! |
|
@snejus Thank you for taking the time to review this! Yeah, I probably should've left it as a draft for now, I pretty much expected some changes would have to be reverted. I did realize that this project uses mypy, but either it doesn't play well with my editor (Zed) or just it's LSP isn't as good as Basedpyright, which is what I'm using. As for the "redundant" type annotations, that's just my personal preference. Sure, you can live without them, but using I just don't like the concept of inferred types at all. They can change without me noticing if I accidentally reuse a variable for an unintended purpose. My goal is to get beets closer to a state where it complies with mypy's strict mode. Although I might suggest migrating to a different type checker like basedpyright at some point. On the other hand, we could wait until pyrefly becomes stable, which is significantly faster then both mypy and basedpyright. I will go over your feedback in detail when I have time and use it as guidance for future contributions. |
Description
I added type hints
and refactored the modules to fix import cyclesTo Do