False "type assignment error" when assigning an instance of Field
class or classes extended from it.
#17043
Labels
bug
mypy got something wrong
Bug Report
1- As you must know, there is no standard way in python to use decorators for defining metadata for a field of a class and the only possible approach is assigning an instance of
Field
class fromdataclass
module to the field. I believe it's weird and irrational but anyway it's now the standard defined in pep 0557 so we expect mypy to follow it.2- there was an issue that describe mypy raising a false "Incompatible types in assignment" error in the simple following code:
3- It seems Sometime around Oct 2023, the problem solved but unfortunately as I can see it solved just in an special condition. in the other words, just when using the
field
factory method.To Reproduce
If you remove the
# type: ignore[assignment]
directive at the end of the following code:(Also
ArgField
is accessible here)mypy will raise errors like:
Expected Behavior
Allow assigning instance of
Field
class or instance of any class extended from it to fields of a dataclass.Actual Behavior
Raising a false
Incompatible types in assignment
errorYour Environment
mypy.ini
(and other config files): nothing specialThe text was updated successfully, but these errors were encountered: