Closed
Description
Bug Report
In code which is checking if a field has a default, a check to see if Field.default_factory is MISSING
will be misreported as a comparison-overlap error if mypy --strict
is used.
To Reproduce
In foo.py
:
from dataclasses import MISSING, Field
from typing import Any
def is_required(x: Field[Any]) -> bool:
return x.default is MISSING and x.default_factory is MISSING
Expected Behavior
This check should pass. One of the valid values for default_factory
is MISSING
.
Actual Behavior
With the above reproduction,
$ mypy --strict foo.py
foo.py:5: error: Non-overlapping identity check (left operand type: "_DefaultFactory[Any]", right operand type: "_MISSING_TYPE")
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
0.931
andmaster
(0.940+dev.84b977876aa76bfebf5fe49d11ebd202e4a60a33
) - Mypy command-line flags:
--strict
- Mypy configuration options from
mypy.ini
(and other config files): None