-
Notifications
You must be signed in to change notification settings - Fork 89
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
chore: add types #225
chore: add types #225
Conversation
Scaffolding in the testing, and will not complete succssfully yet. Will be followed by code changes to pass. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Surfaced via `mypy`, in that an empty dict could not infer what types could be there. Instead of importing `typing` and annotating the empty Dict, I opted to ignore the line, as we do not expect to populate the dict at all, and are using it to **prevent** additions to the value. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Surfaced via `mypy`, recommended adding a type to the empty list. The list was originally empty back in 0.1.0. Instead of adding a type, remove the constant, and the code that uses it from `clean()` - as it was partially reverted in pypa#121. The default `ALLOWED_STYLES` in the underlying library is `[]`. Related: pypa#114 (comment) Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Surfaced via `mypy`, in that the `html.parser` module does not have a direct implementation of `unescape`. Refs: https://docs.python.org/3.6/library/html.html#html.unescape In pypa#192 support for Python 2.7 was removed, the import path changed. This works due to imports placing the imported code in the local scope. If the `html.parser` module ever stopped importing `unescape`, this import would break as a result. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Currently emits a warning: PytestRemovedIn8Warning: The --strict option is deprecated, use --strict-markers instead. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Surfaced by running mypy in strict mode, and added types where relevant. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
The types-docutils hints are still incomplete, good progress is being made. See: python/typeshed#7256 I've had to use an ignore on the class inheritance, and a couple of `typing.Any` annotations until that package implements more type hints. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
`mypy` strict mode is having a hard time with the `distutils` imports, since they are wrapped in `setuptools` right now as a private package. This pacakge's distutils integration will need to be reworked anyhow. Left a comment with details at the top of the file. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Prevent new things from creeping in during development. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Include a blank `py.typed` file in the package to inform `mypy` that there's types to be found in this package. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
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.
Thank you! LGTM, I'll give this ~24 hours for others to review before merging.
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 doing this! At @di's suggestion, I reviewed it based on my experience in Twine. I've got some questions/suggestions about style, but I don't think there's anything that should be considered a blocker.
I confirmed that using this branch allows Twine to remove its mypy ignore for this package.
@bhrutledge Thanks for the review! |
Allows other tools to ebenfit from a consistent configuration. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2d85807
to
710c2e7
Compare
@di would appreciate the CI-approval to get the tests running to confirm. |
# The renderer is a lambda function, and mypy fails lambdas right now. | ||
rendered = renderer(raw) # type: ignore |
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.
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 did not try to modify the code to make the type annotations work - that felt counter to the effort at hand. mypy struggles with lambdas - see open issue: python/mypy#4226
It'd be awesome if you wanted to take on that as a follow-up once this is merged to remove the ignore!
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 again for taking my feedback; it was good exercise for me. :)
Released in https://pypi.org/project/readme-renderer/34.0/. |
With the release of `readme_renderer` 35.0, we no longer need to exclude the library from type evaluation. Refs: pypa/readme_renderer#225 Refs: pypa/readme_renderer#228 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
With the release of `readme_renderer` 35.0, we no longer need to exclude the library from type evaluation. Refs: pypa/readme_renderer#225 Refs: pypa/readme_renderer#228 Signed-off-by: Mike Fiedler <miketheman@gmail.com> Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
As of pypa#225, we now exposed type information to users of the library. Let's also show it via classifier! Signed-off-by: Mike Fiedler <miketheman@gmail.com>
As of pypa#225, we now exposed type information to users of the library. Let's also show it via classifier! Signed-off-by: Mike Fiedler <miketheman@gmail.com>
There's a lot of commits here for a relatively small amount of changes, and it can seem overwhelming at first.
I tried to keep each commit well-scoped, and describe the journey on adding mypy as a testing strategy, correcting the issues surfaced during the initial (non-strict) runs, and then applying stricter rules, until it's finally a fully-typed library.
(I snuck in a pytest warning removal while I was at it.)
Completing this work, and releasing a version should allow us to remove a line in the warehouse config.
Let me know what y'all think!
Resolves #166