Skip to content

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

Closed

Description

@ilevkivskyi

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.

Activity

  1. added
    bug
    topic-plugins
    semantic-analyzer
    on Jun 7, 2019
  2. self-assigned this
    on Jun 12, 2019
  3. added a commit that references this issue on Jun 13, 2019
    7ffcd92
  4. added a commit that references this issue on Jun 13, 2019
    0fdfdc7
  5. added a commit that references this issue on Jun 23, 2019
    1e5f9d8
  6. christoph-blessing commented on Jul 13, 2021

    @christoph-blessing

    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?

  7. JelleZijlstra commented on Jul 13, 2021

    @JelleZijlstra
    Member

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

  8. christoph-blessing commented on Jul 14, 2021

    @christoph-blessing

    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?

  9. JelleZijlstra commented on Jul 14, 2021

    @JelleZijlstra
    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

Metadata

Metadata

Assignees

Labels

bugpriority-0-highsemantic-analyzertopic-plugins

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions