1515)
1616from mypy .erasetype import erase_type
1717from mypy .maptype import map_instance_to_supertype
18-
19- from mypy import experiments
18+ from mypy import state
2019
2120# TODO Describe this module.
2221
@@ -41,7 +40,7 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
4140 for x in declared .relevant_items ()])
4241 elif not is_overlapping_types (declared , narrowed ,
4342 prohibit_none_typevar_overlap = True ):
44- if experiments . STRICT_OPTIONAL :
43+ if state . strict_optional :
4544 return UninhabitedType ()
4645 else :
4746 return NoneTyp ()
@@ -137,7 +136,7 @@ def _is_overlapping_types(left: Type, right: Type) -> bool:
137136 # When running under non-strict optional mode, simplify away types of
138137 # the form 'Union[A, B, C, None]' into just 'Union[A, B, C]'.
139138
140- if not experiments . STRICT_OPTIONAL :
139+ if not state . strict_optional :
141140 if isinstance (left , UnionType ):
142141 left = UnionType .make_union (left .relevant_items ())
143142 if isinstance (right , UnionType ):
@@ -191,7 +190,7 @@ def is_none_typevar_overlap(t1: Type, t2: Type) -> bool:
191190 # We must perform this check after the TypeVar checks because
192191 # a TypeVar could be bound to None, for example.
193192
194- if experiments . STRICT_OPTIONAL and isinstance (left , NoneTyp ) != isinstance (right , NoneTyp ):
193+ if state . strict_optional and isinstance (left , NoneTyp ) != isinstance (right , NoneTyp ):
195194 return False
196195
197196 # Next, we handle single-variant types that may be inherently partially overlapping:
@@ -362,7 +361,7 @@ def __init__(self, s: Type) -> None:
362361
363362 def visit_unbound_type (self , t : UnboundType ) -> Type :
364363 if isinstance (self .s , NoneTyp ):
365- if experiments . STRICT_OPTIONAL :
364+ if state . strict_optional :
366365 return AnyType (TypeOfAny .special_form )
367366 else :
368367 return self .s
@@ -386,7 +385,7 @@ def visit_union_type(self, t: UnionType) -> Type:
386385 return UnionType .make_simplified_union (meets )
387386
388387 def visit_none_type (self , t : NoneTyp ) -> Type :
389- if experiments . STRICT_OPTIONAL :
388+ if state . strict_optional :
390389 if isinstance (self .s , NoneTyp ) or (isinstance (self .s , Instance ) and
391390 self .s .type .fullname () == 'builtins.object' ):
392391 return t
@@ -400,7 +399,7 @@ def visit_uninhabited_type(self, t: UninhabitedType) -> Type:
400399
401400 def visit_deleted_type (self , t : DeletedType ) -> Type :
402401 if isinstance (self .s , NoneTyp ):
403- if experiments . STRICT_OPTIONAL :
402+ if state . strict_optional :
404403 return t
405404 else :
406405 return self .s
@@ -430,7 +429,7 @@ def visit_instance(self, t: Instance) -> Type:
430429 args .append (self .meet (t .args [i ], si .args [i ]))
431430 return Instance (t .type , args )
432431 else :
433- if experiments . STRICT_OPTIONAL :
432+ if state . strict_optional :
434433 return UninhabitedType ()
435434 else :
436435 return NoneTyp ()
@@ -441,7 +440,7 @@ def visit_instance(self, t: Instance) -> Type:
441440 # See also above comment.
442441 return self .s
443442 else :
444- if experiments . STRICT_OPTIONAL :
443+ if state . strict_optional :
445444 return UninhabitedType ()
446445 else :
447446 return NoneTyp ()
@@ -559,7 +558,7 @@ def default(self, typ: Type) -> Type:
559558 if isinstance (typ , UnboundType ):
560559 return AnyType (TypeOfAny .special_form )
561560 else :
562- if experiments . STRICT_OPTIONAL :
561+ if state . strict_optional :
563562 return UninhabitedType ()
564563 else :
565564 return NoneTyp ()
0 commit comments