Skip to content

TYP: typing errors for mypy==0.790 #37104

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

Closed
fangchenli opened this issue Oct 13, 2020 · 4 comments · Fixed by #37108
Closed

TYP: typing errors for mypy==0.790 #37104

fangchenli opened this issue Oct 13, 2020 · 4 comments · Fixed by #37108
Labels
Typing type annotations, mypy/pyright type checking

Comments

@fangchenli
Copy link
Member

mypy pandas
pandas/core/computation/parsing.py:41: error: unused 'type: ignore' comment
pandas/io/common.py:452: error: Unsupported operand types for + ("List[Optional[str]]" and "List[str]")  [operator]
pandas/core/aggregation.py:483: error: Value of type variable "_LT" of "sorted" cannot be "Optional[Hashable]"  [type-var]
pandas/core/aggregation.py:606: error: Value of type variable "_LT" of "sorted" cannot be "Optional[Hashable]"  [type-var]
pandas/core/groupby/ops.py:270: error: Incompatible types in assignment (expression has type "Index", variable has type "Iterator[Any]")  [assignment]
pandas/core/groupby/ops.py:270: note: 'Index' is missing following 'Iterator' protocol member:
pandas/core/groupby/ops.py:270: note:     __next__
Found 5 errors in 4 files (checked 1057 source files)
@fangchenli fangchenli added Bug Needs Triage Issue that has not been reviewed by a pandas team member Typing type annotations, mypy/pyright type checking and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 13, 2020
@jreback jreback added this to the 1.2 milestone Oct 14, 2020
@dsaxton
Copy link
Member

dsaxton commented Oct 15, 2020

Is the error for L452 in common.py right? Seems fine to add a list of strings and None to a list of strings.

@simonjayhawkins
Copy link
Member

simonjayhawkins commented Oct 16, 2020

This seems a common issue in expressions with concatinating lists. Mypy inference determines the type from the first sequence.

when assigning the result, then it is the type of the result that is important, so these errors could be considered false positives.

It is quite messy to add casts to resolve these, so ignores are probably OK.

It is possible to refactor, using unpacking, so that mypy doesn't complain, but I don't think this method gets universal approval. i.e.

["foo", None] + [1, 2, 3] -> ["foo", None, *[1, 2, 3]]

@jreback jreback modified the milestones: 1.2, Contributions Welcome Nov 25, 2020
@simonjayhawkins
Copy link
Member

pandas/core/aggregation.py:483: error: Value of type variable "_LT" of "sorted" cannot be "Optional[Hashable]"  [type-var]
pandas/core/aggregation.py:606: error: Value of type variable "_LT" of "sorted" cannot be "Optional[Hashable]"  [type-var]

These are not false positives...

>>> sorted([None,1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'int' and 'NoneType'
>>> sorted([1, "foo"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'int'
>>> 

opened #39025 for one of the cases

@simonjayhawkins
Copy link
Member

due to recent changes we have an additional mypy error

pandas/io/common.py:182: error: Only @runtime_checkable protocols can be used with instance and class checks  [misc]

may need to revert #38018. further investigation (and code sample) on whether there was a regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants