Fix decorator typing with _Decorator type alias #2559
Closed
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.
_Decorator[FC]
is identical tot.Callable[[FC], FC]
. However,mypy
currently reads the first type incorrectly and supports the second one fully.This fix will make mypy checking work correctly on click decorators, and should have no negative impact on other type checkers because the types are effectively "the same".
I plan to open a bug report against
mypy
to ask about this issue. It may be a duplicate (python/mypy#13250 ?), but we'll have a thread to pull on there to figure out why this isn't supported when there doesn't appear to be a meaningful difference between the two types.Checklist:
I haven't added tests because any
mypy
testing will require some kind of new framework for testing types.I think this would be valuable and not hard (e.g. here's some prior art in marshmallow which I helped setup), but it's beyond the scope of a small typing fix.
Instead, I tested
mypy
v1.4.1 (latest) before and after this change on the following small sample:Before the change:
After the change:
(N/A) Add or update relevant docs, in the docs folder and in code.
Add an entry in
CHANGES.rst
summarizing the change and linking to the issue.I added a changelog section for 8.1.5 since this is the first change after 8.1.4. I'm happy to make tweaks and changes if this was not appropriate.
.. versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.