Skip to content
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

New semantic analyzer: plugin generated methods are confused with user defined ones #6954

Closed
ilevkivskyi opened this issue Jun 7, 2019 · 4 comments · Fixed by #6987
Closed
Assignees
Labels
bug mypy got something wrong priority-0-high semantic-analyzer Problems that happen during semantic analysis topic-plugins The plugin API and ideas for new plugins

Comments

@ilevkivskyi
Copy link
Member

This test case fails with new analyzer (note deferral):

[case testDataclassOrdering]
# flags: --python-version 3.6
from dataclasses import dataclass

defer: Yes

@dataclass(order=True)
class Application:
  name: str
  rating: int

class Yes: ...
[builtins fixtures/list.pyi]

with a bunch of errors

main:7: error: You may not have a custom __lt__ method when order=True
main:7: error: You may not have a custom __gt__ method when order=True
main:7: error: You may not have a custom __le__ method when order=True
main:7: error: You may not have a custom __ge__ method when order=True

Setting priority to high because it is a flaw in basic plugin functionality.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-0-high topic-plugins The plugin API and ideas for new plugins semantic-analyzer Problems that happen during semantic analysis labels Jun 7, 2019
@JukkaL JukkaL self-assigned this Jun 12, 2019
@christoph-blessing
Copy link

christoph-blessing commented Jul 13, 2021

I think I am experiencing a related issue with mypy 0.910. Here is the offending code:

from collections.abc import Set
from dataclasses import dataclass

@dataclass(order=True)
class MySet(Set):
    pass

And here are the errors it produces:

test.py: error: You may not have a custom __lt__ method when order=True
test.py: error: You may not have a custom __gt__ method when order=True
test.py: error: You may not have a custom __le__ method when order=True
test.py: error: You may not have a custom __ge__ method when order=True
test.py:5: error: Only concrete class can be given where "Type[MySet]" is expected
test.py:6: error: Argument 1 of "__lt__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: note: This violates the Liskov substitution principle
test.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
test.py:6: error: Argument 1 of "__gt__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: error: Argument 1 of "__le__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
test.py:6: error: Argument 1 of "__ge__" is incompatible with supertype "AbstractSet"; supertype defines the argument type as "AbstractSet[Any]"
Found 9 errors in 1 file (checked 1 source file)

Setting order=False gets rid of all errors except this one:

test.py:5: error: Only concrete class can be given where "Type[MySet]" is expected

It also seems to be related to Set and MutableSet from collections.abc. I don't get this behavior with Mapping for example.

Any ideas what is happening here?

@JelleZijlstra
Copy link
Member

Could you open a new issue? This is likely related to the typeshed definition for Set, so that's where I'd look.

@christoph-blessing
Copy link

Could you open a new issue? This is likely related to the typeshed definition for Set, so that's where I'd look.

Should I open the new issue in the mypy repo or in the typeshed repo?

@JelleZijlstra
Copy link
Member

Let's start with mypy and transfer to typeshed if we find a concrete problem in the stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high semantic-analyzer Problems that happen during semantic analysis topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants