-
Notifications
You must be signed in to change notification settings - Fork 55
Add strict types to the entire library #187
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: main
Are you sure you want to change the base?
Conversation
|
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. |
9ca9be5 to
2d0b9b6
Compare
amogus07
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.
I don't have much experience with libraries, but here are some ideas and suggestions
| @@ -1 +1 @@ | |||
| import yaml | |||
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.
| import yaml.scanner |
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?
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.
From the underlying loaded modules in sys.modules it should make no difference. The yaml module does not use any lazy loading afaiks.
For maintenance reasons I would just import what we acutely use instead of importing the full module if there is no specific reason for it. I.e.from yaml.scanner import ScannerError.
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.
Won't importing yaml execute it's __init__.py, which is unnecessary overhead?
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.
Yes but importing yaml.scanner will also execute the yaml/__init__.py file. You can readup on the exact semantics here.
f7ffcd3 to
8afaaab
Compare
df5fe80 to
3f7059e
Compare
|
@amogus07 I noticed that several of your comments are based on issues raised by Mypy balances strictness with pragmatism, while
We prefer Mypy's approach for library maintenance. If you're contributing to |
|
@snejus I suppose it's just a matter of preference. Whereas you see stricter rules as a cognitive burden, I often have a hard time understanding untyped or leniently typed code (as it's easy to misunderstand it from an outsider perspective). I understand that this project uses mypy, I just thought some of (based)pyright's suggestions are also worth considering as long as they don't conflict with mypy. But if you're strictly against it I'll try to keep that in mind. |
This PR adds types to the library and includes
py.typedso thatmypydiscovers them in packages that depend onconfuse.I have tested this against
beets: it makes complicated templates, such asMappingTemplate,OneOfandChoicestransparent, for example: