mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Improvements to descriptor `__set__`

Open bzoracler opened this issue 1 year ago • 2 comments

  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
    

    https://github.com/python/mypy/commit/e570aa1cd8b964a7c32b8a6d1bcefd8d8da4d4db will change the error location to be on the left:

    >>> abc: A = A()
    >>> abc.prop = 123
        ^~~~~~~~
        E
    
  2. Fixes #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.

bzoracler avatar Apr 25 '24 06:04 bzoracler

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

github-actions[bot] avatar Apr 25 '24 06:04 github-actions[bot]

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

github-actions[bot] avatar Apr 29 '24 11:04 github-actions[bot]