Skip to content

Conversation

@amogus07
Copy link
Contributor

@amogus07 amogus07 commented Oct 24, 2025

Description

I added type hints and refactored the modules to fix import cycles

To Do

  • Documentation
  • Changelog
  • Tests

@amogus07 amogus07 requested review from a team and semohr as code owners October 24, 2025 00:51
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

@github-actions
Copy link

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.

@semohr
Copy link
Contributor

semohr commented Oct 24, 2025

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!

@amogus07 amogus07 changed the title refactor util and ui + add lots of type hints add lots of type hints Oct 24, 2025
Copy link
Member

@snejus snejus left a 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()
Copy link
Member

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:
Copy link
Member

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 = (
Copy link
Member

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]]:
Copy link
Member

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]):
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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:
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.

@snejus
Copy link
Member

snejus commented Oct 29, 2025

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 pyright to type check this project. In an ideal world, pyright and mypy would show the same issues, but they don't in reality. This project uses mypy as our type checker, so changes should address mypy's requirements rather than pyright's. Some of these type hints may be fixing issues that pyright sees but mypy doesn't, because it manages to resolve the types.

Would you mind running mypy on your changes to see which type issues actually need addressing for our setup? That would help focus the PR on changes that are truly necessary. Please use resolve_type to see whether a type is missing for a variable.

Thanks again for your effort on this - I really do appreciate it!

@amogus07
Copy link
Contributor Author

@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.

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