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

Improvements to descriptor __set__ #17170

Closed
wants to merge 3 commits into from

Conversation

bzoracler
Copy link
Contributor

  1. Fix wrong error location when assignment errors is due to __set__. Presently, the error location appears on the right:

    # mypy: pretty=True
    
    import typing as t
    
    class desc:
        __set__ = None
        
    class A:
        prop = desc()
    >>> abc: A = A()
    >>> abc.prop = 123
                   ^~~
                   E

    e570aa1 will change the error location to be on the left:

    >>> abc: A = A()
    >>> abc.prop = 123
        ^~~~~~~~
        E
  2. Fixes Descriptors and ClassVars #14969

    • The example in the issue will still error because ClassVar there is not specified with a type (an unannotated ClassVar is equivalent to ClassVar[Any]).
    • Unlike in other annotation contexts, I didn't think it was a good idea to be permissive with Any, due to the potential creep of false negatives.

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@bzoracler bzoracler closed this by deleting the head repository May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Descriptors and ClassVars
1 participant