Skip to content

Commit 1a95964

Browse files
Make join and meet symmetric with strict_optional (#18227)
Fixes #18199 Updated `join.py` to return `AnyType(TypeOfAny.special_form)` for both `UnboundType` and `AnyType`. Updated `meet.py` to return `UninhabitedType()` when visiting a `UnboundType` as a `NoneType` when `state.strict_optional` is true.
1 parent e666217 commit 1a95964

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

mypy/join.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def visit_none_type(self, t: NoneType) -> ProperType:
317317
if state.strict_optional:
318318
if isinstance(self.s, (NoneType, UninhabitedType)):
319319
return t
320-
elif isinstance(self.s, UnboundType):
320+
elif isinstance(self.s, (UnboundType, AnyType)):
321321
return AnyType(TypeOfAny.special_form)
322322
else:
323323
return mypy.typeops.make_simplified_union([self.s, t])

mypy/meet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def __init__(self, s: ProperType) -> None:
691691
def visit_unbound_type(self, t: UnboundType) -> ProperType:
692692
if isinstance(self.s, NoneType):
693693
if state.strict_optional:
694-
return AnyType(TypeOfAny.special_form)
694+
return UninhabitedType()
695695
else:
696696
return self.s
697697
elif isinstance(self.s, UninhabitedType):

mypy/test/testtypes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,7 @@ def test_any_type(self) -> None:
806806
self.fx.anyt,
807807
self.fx.a,
808808
self.fx.o,
809-
# TODO: fix this is not currently symmetric
810-
# NoneType(),
809+
NoneType(),
811810
UnboundType("x"),
812811
self.fx.t,
813812
self.tuple(),
@@ -1177,8 +1176,7 @@ def test_none(self) -> None:
11771176
self.assert_meet(self.fx.o, NoneType(), NoneType())
11781177
for t in [
11791178
self.fx.a,
1180-
# TODO: fix this is not currently symmetric
1181-
# UnboundType("x"),
1179+
UnboundType("x"),
11821180
self.fx.t,
11831181
self.tuple(),
11841182
self.callable(self.fx.a, self.fx.b),

0 commit comments

Comments
 (0)