-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
WIP for MyPy CI Integration #25622
WIP for MyPy CI Integration #25622
Conversation
Hello @WillAyd! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-03-11 19:40:33 UTC |
mypy.ini
Outdated
@@ -0,0 +1,8 @@ | |||
[mypy] | |||
follow_imports=silent |
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.
This is less than ideal but without this the errors are out of control. My motivation for setting this comes from the Mypy documentation:
https://mypy.readthedocs.io/en/latest/running_mypy.html#following-imports
To wit:
If you are planning on adding type hints to a large, existing code base, we recommend you start by trying to make your entire codebase (including files that do not use type hints) pass under --follow-imports=normal. This is usually not too difficult to do: mypy is designed to report as few error messages as possible when it is looking at unannotated code.
If doing this is intractable, we recommend passing mypy just the files you want to type check and use --follow-imports=silent. Even if mypy is unable to perfectly type check a file, it can still glean some useful information by parsing it (for example, understanding what methods a given object has). See Using mypy with an existing codebase for more recommendations.
mypy.ini
Outdated
[mypy-numpy.*] | ||
ignore_missing_imports=True | ||
|
||
[mypy-pandas._libs.*] |
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.
Generally doesn't look like Mypy likes Cython imports. Have this in the config but also noted specifically on imports within the code.
There's probably a better approach to this just haven't found yet
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.
According to the PEP, you should be able to use .pyi/stub files to annotate compiled extensions. Not ideal though since they'd have to stay in-sync with the extension
@@ -0,0 +1,17 @@ | |||
pandas/core/dtypes/base.py |
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.
These are all of the files that currently have some sort of hints in them. The motivation for this comes form this part in the documentation:
https://mypy.readthedocs.io/en/latest/running_mypy.html#reading-a-list-of-files-from-a-file
So thinking for initial CI runs we can whitelist the modules we want to run against, though this is ideally just a temporary file
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.
To be clear when running this from the project root you would do mypy @mypy_whitelist.txt
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.
@Naddiseo any chance you have experience with this? Reading from docs I think suggested approach will be to whitelist particular modules at the outset and slowly open up as more are added.
I'd like to avoid having two files to control configuration here but I don't see an easy way in the .ini
file to control which modules actually get checked
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.
@WillAyd, not with the whitelist approach. I went with the blacklist approach instead, and had a bunch of modules and packages with ignore_errors
set.
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 the feedback. Was that done per package / module in the config file?
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.
Currently I'm just ignoring packages. But, I think at one point I was doing both, and I seem to remember doing a mixture where I'd ignore everything in a package except a specific file.
I think it looked like:
[mypy-package.subpackage]
ignore_errors=True
[mypy-package.subpackage.module]
ignore_errors=False
However, I don't remember if it worked or not.
|
||
import numpy as np | ||
|
||
from pandas._libs import Timestamp, groupby as libgroupby | ||
from pandas._libs import Timestamp, groupby as libgroupby # 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.
See note on Cython imports
One issue in existings that I wasn't sure how to resolve stems from the ExtensionBlock in internals, specifically this line: pandas/pandas/core/internals/blocks.py Line 1693 in e28ae70
It's superclass and all other subclasses derived therefrom treat this as an attribute, whereas here it's a property. I think that's the root of the issue |
Interesting issue, it might be a bug in mypy. Although, it might also be a legitimate typing error: my guess would be that mypy is saying "you told me it's a property, so I expect that I can do |
.gitignore
Outdated
@@ -111,4 +112,4 @@ doc/build/html/index.html | |||
# Windows specific leftover: | |||
doc/tmp.sv | |||
env/ | |||
doc/source/savefig/ | |||
doc/source/savefig/ |
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.
need a newline here
pandas/core/groupby/groupby.py | ||
pandas/core/internals/blocks.py | ||
pandas/core/internals/managers.py | ||
pandas/core/common.py |
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 is this not possible in the setup file?
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.
Yea I was hoping that Mypy_path
in the ini file would work but didn't have any luck. I didn't also see a very good way to make this readable therein since the ini would expect this to be a comma separated list.
With that said this may just be temporary anyway - would ideally like to run on the entire code. Modules without existing types would be ignored by default anyway
Codecov Report
@@ Coverage Diff @@
## master #25622 +/- ##
==========================================
+ Coverage 91.26% 91.26% +<.01%
==========================================
Files 173 173
Lines 52968 52974 +6
==========================================
+ Hits 48339 48345 +6
Misses 4629 4629
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25622 +/- ##
==========================================
+ Coverage 91.26% 91.26% +<.01%
==========================================
Files 173 173
Lines 52968 52992 +24
==========================================
+ Hits 48339 48364 +25
+ Misses 4629 4628 -1
Continue to review full report at Codecov.
|
Changes so far were low effort fixes. Here's what's left when running pandas/core/base.py:853: error: "IndexOpsMixin" has no attribute "_values"; maybe "_map_values"?
pandas/core/base.py:978: error: "IndexOpsMixin" has no attribute "values"
pandas/core/arrays/array_.py:235: error: Item "str" of "Union[str, Any, ExtensionDtype, None]" has no attribute "construct_array_type"
pandas/core/arrays/array_.py:235: error: Item "None" of "Union[str, Any, ExtensionDtype, None]" has no attribute "construct_array_type"
pandas/core/arrays/datetimelike.py:365: error: "DatetimeLikeArrayMixin" has no attribute "_data"
pandas/core/arrays/datetimelike.py:466: error: Name 'Scalar' is not defined
pandas/core/arrays/datetimelike.py:482: error: Argument 1 to "len" has incompatible type "Union[int, Sequence[int], Sequence[bool], slice]"; expected "Sized"
pandas/core/arrays/datetimelike.py:486: error: Argument 1 to "len" has incompatible type "Union[int, Sequence[int], Sequence[bool], slice]"; expected "Sized"
pandas/core/arrays/datetimelike.py:487: error: Argument 1 to "len" has incompatible type "Union[int, Sequence[int], Sequence[bool], slice]"; expected "Sized"
pandas/core/arrays/datetimelike.py:503: error: Item "Tuple[Any, ...]" of "Union[type, Tuple[type]]" has no attribute "__name__"
pandas/core/arrays/datetimelike.py:505: error: "DatetimeLikeArrayMixin" has no attribute "_data"
pandas/core/arrays/sparse.py:80: error: Incompatible types in assignment (expression has type "Tuple[str, str, str]", base class "_DtypeOpsMixin" defined the type as "Tuple[]")
pandas/core/arrays/period.py:189: error: "PeriodDtype" has no attribute "freq"
pandas/core/arrays/period.py:278: error: Read-only property cannot override read-write property
pandas/core/arrays/period.py:544: error: The first argument to Callable must be a list of types or "..."
pandas/core/arrays/period.py:550: error: Unsupported operand type for unary - ("Union[Index, ExtensionArray, Any]")
pandas/core/arrays/period.py:784: error: Incompatible types in assignment (expression has type "None", variable has type "PeriodDtype")
pandas/core/arrays/integer.py:34: error: Incompatible types in assignment (expression has type "None", base class "ExtensionDtype" defined the type as "str")
pandas/core/arrays/integer.py:36: error: Incompatible types in assignment (expression has type "None", base class "ExtensionDtype" defined the type as "Type[Any]")
pandas/core/indexes/datetimelike.py:65: error: "Callable[[Any], Any]" has no attribute "fget"
pandas/core/indexes/datetimelike.py:66: error: "Callable[[Any], Any]" has no attribute "fget"
pandas/core/indexes/datetimelike.py:67: error: "Callable[[Any], Any]" has no attribute "fget"
pandas/core/indexes/datetimelike.py:69: error: "Callable[[Any], Any]" has no attribute "fget"
pandas/core/indexes/datetimelike.py:70: error: "Callable[[Any], Any]" has no attribute "fget"
pandas/core/indexes/datetimelike.py:136: error: "DatetimeLikeArrayMixin" has no attribute "_data"
pandas/core/indexes/datetimelike.py:138: error: Decorated property not supported
pandas/core/indexes/datetimelike.py:208: error: Name '_box_values' already defined on line 72
pandas/core/indexes/period.py:68: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas/core/indexes/period.py:68: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "DatetimelikeDelegateMixin"
pandas/core/indexes/period.py:68: error: Definition of "map" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas/core/indexes/period.py:68: error: Definition of "_format_with_header" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas/core/indexes/period.py:68: error: Definition of "isin" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas/core/internals/blocks.py:2218: error: Definition of "_can_hold_na" in base class "ExtensionBlock" is incompatible with definition in base class "DatetimeBlock" Some of these will actually require a refactor of code. Probably want to split off into pre-cursor or at least separate PRs to tackle |
Somewhat superseded by #25789 - there are some things here I'd like to extract out but easier to start fresh than merge master at this point |
progress towards #25601
Not complete just pushing for now. Main goal here is to get a CI run that works for any modules existing with comments.