-
Notifications
You must be signed in to change notification settings - Fork 1
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
Reevaluate & fix types (now with stubs!) #119
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gtronset
changed the title
Add typehints & fix types
Reevaluate & fix types (now with stubs!)
Nov 16, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This is a comprehensive reevaluation of the type hints used by Filetote. With recent excellent efforts by Beets contributors (ex: beetbox/beets#4591), much more of beets has typing which means less guessing needs to occur and that stubs can be built out (recognizing the type hints added to beets are not yet released; stubs for it will be removed at a later date once possible).
This adds Type Hint Stubs for the following, which allows for the removal of
--ignore-missing-imports
from MyPy:This also adds linting for
.pyi
(stub) files courtesy of flake8-pyi. As part of that, Flake8's config was extended for better compatibility with other linting/formatting (see: e5f94b3).This also adds typeguard to run during pytests. Note: that functionality is disabled in Python 3.6 due to a bug in the last version of
typeguard
for it (see: agronholm/typeguard#168).Finally, validation for the Filetote config has been added to ensure that at least the correct types are being set in the config itself.
Bonuses: deprecation warning for libraries used by
confuse
andmediafile
are now ignored in Pytest; CI's running of pytest will be slightly faster.A note on Paths
Beets has a long blog post on its strategy of handling path types; TL;DR they've opted to handle them everywhere as bytestrings (
bytes
). This plugin (and its predecessorcopyartifacts
) would use them interchangeably. This has been updated with the help of better type hints and the changes mentioned above.While not documented explicitly,
MoveOperation
-related events expectbytes
-type paths for theirsource
anddestination
parameters. This was discovered by digging deeper here: https://github.com/beetbox/beets/blob/708a04d4a88eb955f261a21f0b1146c9e2ae0a55/beets/library.py#L915Bugs fixed in this:
pairing
setting/node (filetote.pairing.extensions
would not come through as a string sequence)Future Changes
Additional refactoring is needed in the core handling of files to simplify and make it easier to understand. In particular relevance to this PR, there might be additional typing issues hidden in some of thee deeper parts that were not addressed here, due to the nature of how those methods are written.