# type: ignore[assignment] on the except ImportError: x = None fallback in serializer.py (pyarrow) and document_base.py (annotationlib, UnionType) flips between needed/unused depending on mypy/pyarrow-stubs/Python version. Hit twice already: generates_9.5_code (6b0aa4e, 408d9c9) and main (#3475). #3475 suppressed it via a module-wide warn_unused_ignores = false override, which also hides any real unused-ignore added to those files later.
Fix: split type-checking and runtime import paths, mypy always resolves the if branch, the else is never type-checked (verified: no error with pyarrow installed, uninstalled, or a garbage assignment in the except).
if TYPE_CHECKING:
import pyarrow as pa
else:
try:
import pyarrow as pa
...
__all__.append("PyArrowSerializer")
except ImportError:
pa = None
Same shape for annotationlib and UnionType. Remove the two overrides from pyproject.toml.
Rejected: annotate pa: Optional[ModuleType] upfront, skip the split. Fails with no-redef, mypy treats the annotation and the import as conflicting.
Effort: ~30-60 min, 2 files, verify across the Python version matrix.
# type: ignore[assignment]on theexcept ImportError: x = Nonefallback inserializer.py(pyarrow) anddocument_base.py(annotationlib, UnionType) flips between needed/unused depending on mypy/pyarrow-stubs/Python version. Hit twice already:generates_9.5_code(6b0aa4e, 408d9c9) and main (#3475). #3475 suppressed it via a module-widewarn_unused_ignores = falseoverride, which also hides any real unused-ignore added to those files later.Fix: split type-checking and runtime import paths, mypy always resolves the
ifbranch, theelseis never type-checked (verified: no error with pyarrow installed, uninstalled, or a garbage assignment in the except).Same shape for
annotationlibandUnionType. Remove the two overrides frompyproject.toml.Rejected: annotate
pa: Optional[ModuleType]upfront, skip the split. Fails withno-redef, mypy treats the annotation and the import as conflicting.Effort: ~30-60 min, 2 files, verify across the Python version matrix.