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

Importer typehints and small importer refactor #5611

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

semohr
Copy link

@semohr semohr commented Feb 1, 2025

Description

Hello y'all.

One of the dev from the beets-flask app here. We are extending the ImportSession in our application to get the interactive imports working in our application. Overall that was not a too pleasant experience as a ton of typehints are missing in that area of the beets code. This PR wants to fix this ;)

Changes

Moved importer state logic into a dataclass. Is clearer and more isolated now in my opinion, we are not using it but I found it quite confusing when looking at it.

Added a ton of typehints to the importer.py file. Predominantly the ImportSession, ImportTask (and derivatives) and pipeline stage decorators are now (hopefully) completely typed. Additionally I fixed some typhint issues in the util.__init__.py file, mainly related to the PathLike type.

If you have some strong opinions about any of the changes feel free to revert or edit the PR.

Best,
Sebastian

P.S: I noticed that beets does not use Abstract Base Classes is there any reason for that or is it just of historic nature? I think some Base Classes could be adapted to use an ABC metaclass quite easily.

To Do

  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests finish successfully locally

Copy link

github-actions bot commented Feb 1, 2025

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
Author

semohr commented Feb 1, 2025

There is one failing tests that has, as far as I can see, nothing to do with any of the changes in the PR. Some help would be highly appreciated here.

@snejus
Copy link
Member

snejus commented Feb 1, 2025

I'm now looking at the test as that's something that I merged earlier, apologies!

test/plugins/test_lyrics.py Outdated Show resolved Hide resolved
semohr and others added 3 commits February 3, 2025 11:37
The return type of the stage decorator should in theory be `T|None`
but the return of task types is not consistent in its usage. Would need
some bigger changes for which I'm not ready at the moment.
@semohr semohr force-pushed the importer-typehints-and-refactor branch from 9bbb22d to 34101c2 Compare February 7, 2025 15:50
@semohr
Copy link
Author

semohr commented Feb 7, 2025

I just merged the master into this branch, but the test still seems to be broken. Tried to fix it but tbh I have no idea what the issue is here, as I don't have much insights into how the lyrics plugin works. It is also difficult to debug as the issue does not occur locally for me. From my side feel free to merge this!

I might make another PR in the near future for some changes related to the pipeline, especially modernizing it a bit.

@snejus
Copy link
Member

snejus commented Feb 8, 2025

Apologies, I haven't yet addressed the lyrics issue... 🤦🏼

@snejus
Copy link
Member

snejus commented Feb 8, 2025

The fix is up #5618

@semohr
Copy link
Author

semohr commented Feb 8, 2025

Don't stress it! Was just checking it again and wasn't able to fix it myself.

@snejus snejus mentioned this pull request Feb 8, 2025
@snejus
Copy link
Member

snejus commented Feb 8, 2025

It's been merged - feel free to rebase / merge now! Will have a look at the types you added now, coincidentally I've been doing the same in my fork, so I'm intrigued! 😉

@semohr
Copy link
Author

semohr commented Feb 8, 2025

Awesome! If you want feel free to check my async-import branch too. I added some more type hints there too, will maybe make a PR once this is a bit more polished and it is fully backwards compatible.

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.

Added a couple of comments, note I will have another look once these are addressed, thanks!

beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/util/__init__.py Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
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.

Noticed that typing.cast is being used - unfortunately it tends to hide typing issues. Added some suggestions how to replace it

beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
beets/importer.py Outdated Show resolved Hide resolved
@semohr semohr mentioned this pull request Feb 9, 2025
beets/util/pipeline.py Outdated Show resolved Hide resolved
@snejus
Copy link
Member

snejus commented Feb 9, 2025

See the last two bits in unresolved conversations - otherwise we'll be good to go!

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.

2 participants