-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: enable disallow_untyped_decorators #43828
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
Conversation
The failure from the web-docs:
seems unrelated, but it looks legit. |
yah there are several methods near the top of DatetimeIndex that are there instead of using the decorator for this reason, most of the "# methods that dispatch to DatetimeArray and wrap result" section |
So the solution is to write a doc-string? I'm surprised that this warning/error occurs only for this PR. The 1.3.3 documentation of DatetimeIndex has the same issue: |
IIRC the motivation was for mypy, not docstrings. the decorator should handle docstrings correctly. |
The decorator seems to handle doc-strings correctly, all other attributes (for example I will write a doc-string in a separate PR. But I don't understand why this PR causes this issue. |
Should be ready for review :) |
return result.view(self.dtype) | ||
# error: Incompatible return value type (got "Union[ExtensionArray, | ||
# ndarray[Any, Any]]", expected "PeriodArray") | ||
return result.view(self.dtype) # type: ignore[return-value] |
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.
in pandas/core/arrays/datetimelike.py we overloaded view for DatetimeLikeArrayMixin. maybe could do the same for PeriodArray. (suggestion, not necessarily for this PR)
# expected "Index" | ||
levels = [ping.group_index for ping in self.grouper.groupings] + [ | ||
lev # type: ignore[list-item] | ||
] |
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.
hmm, we have a Union return type from factorize
.
Over time we should avoid Union return types, either through refactoring code or using overloads.
from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions
avoid union return types: python/mypy#1693;
(comment, no action needed for this PR)
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 @twoertwein very nice. some comments and suggestions but none blockers.
maybe open an issue after this is merged. |
(or use module level pyright comment syntax) |
SGTM |
Rebased and addressed the big comments. If it is green, it should be ready for merging from my perspective. |
sure. @jreback @jbrockmendel any further comments? |
There is something failing related due to the numba wrapper, will debug that |
I think numba analyzes the source code to JIT it. I think the errors are a results of jitting a function that itself has a jitted function where the inner function is jitted with |
I think I have to revert the numba-wrapper: https://numba.pydata.org/numba-doc/dev/reference/pysupported.html#functions-as-arguments. It would be great to clean up all the ignore statement for @simonjayhawkins let me know if you see a simple non-intrusive way that could avoid the ignore statements for this PR. Otherwise, I will revert the commit that added |
no problem leaving that out of this PR. The method I'm working with would not prevent the ignores but does providing typing for the "pandas lib api". I use that term loosely as meaning anything coded in Cython, as this is otherwise not formalized. https://github.com/simonjayhawkins/pandas/blob/ec8f0397b5c4a232e8e3e7abfbec91e9ea33016a/pandas/_libs_numba/algos.py#L245-L255 It'll probably be better to write out own stubs for now and include them in the main repo |
I removed the numba wrapper and rebased |
The isinstance change and rebased after #44144 |
@twoertwein can you resolve conflicts |
i've opened #44233 that we could maybe merge after this. |
Great! I'll rebase this PR to resolve the conflicts with master. |
Hello @twoertwein! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-10-30 11:55:31 UTC |
nice thanks @twoertwein and @simonjayhawkins for the review. |
Some of the many type errors unveiled by
cache_readonly
might be easily fixable. This PR simply ignores all the uncovered errors to quickly enable mypy'sdisallow_untyped_decorators
to prevent future untyped decorators.I enabled mypy's
disallow_untyped_decorators
but pyright'sreportUntypedFunctionDecorator
finds the following three functions that are not found by mypy, so I didn't enablereportUntypedFunctionDecorator
(can't add ignore statements, otherwise mypy will complain about unused ignore statements, edit: using pyright's file-based ignore comments):pandas/core/util/numba_.py:93