mypy
mypy copied to clipboard
Improvements to descriptor `__set__`
-
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 ^~~ Ehttps://github.com/python/mypy/commit/e570aa1cd8b964a7c32b8a6d1bcefd8d8da4d4db will change the error location to be on the left:
>>> abc: A = A() >>> abc.prop = 123 ^~~~~~~~ E -
Fixes #14969
- The example in the issue will still error because
ClassVarthere is not specified with a type (an unannotatedClassVaris equivalent toClassVar[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.
- The example in the issue will still error because
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅