15
15
)
16
16
from mypy .erasetype import erase_type
17
17
from mypy .maptype import map_instance_to_supertype
18
-
19
- from mypy import experiments
18
+ from mypy import state
20
19
21
20
# TODO Describe this module.
22
21
@@ -41,7 +40,7 @@ def narrow_declared_type(declared: Type, narrowed: Type) -> Type:
41
40
for x in declared .relevant_items ()])
42
41
elif not is_overlapping_types (declared , narrowed ,
43
42
prohibit_none_typevar_overlap = True ):
44
- if experiments . STRICT_OPTIONAL :
43
+ if state . strict_optional :
45
44
return UninhabitedType ()
46
45
else :
47
46
return NoneTyp ()
@@ -137,7 +136,7 @@ def _is_overlapping_types(left: Type, right: Type) -> bool:
137
136
# When running under non-strict optional mode, simplify away types of
138
137
# the form 'Union[A, B, C, None]' into just 'Union[A, B, C]'.
139
138
140
- if not experiments . STRICT_OPTIONAL :
139
+ if not state . strict_optional :
141
140
if isinstance (left , UnionType ):
142
141
left = UnionType .make_union (left .relevant_items ())
143
142
if isinstance (right , UnionType ):
@@ -191,7 +190,7 @@ def is_none_typevar_overlap(t1: Type, t2: Type) -> bool:
191
190
# We must perform this check after the TypeVar checks because
192
191
# a TypeVar could be bound to None, for example.
193
192
194
- if experiments . STRICT_OPTIONAL and isinstance (left , NoneTyp ) != isinstance (right , NoneTyp ):
193
+ if state . strict_optional and isinstance (left , NoneTyp ) != isinstance (right , NoneTyp ):
195
194
return False
196
195
197
196
# Next, we handle single-variant types that may be inherently partially overlapping:
@@ -362,7 +361,7 @@ def __init__(self, s: Type) -> None:
362
361
363
362
def visit_unbound_type (self , t : UnboundType ) -> Type :
364
363
if isinstance (self .s , NoneTyp ):
365
- if experiments . STRICT_OPTIONAL :
364
+ if state . strict_optional :
366
365
return AnyType (TypeOfAny .special_form )
367
366
else :
368
367
return self .s
@@ -386,7 +385,7 @@ def visit_union_type(self, t: UnionType) -> Type:
386
385
return UnionType .make_simplified_union (meets )
387
386
388
387
def visit_none_type (self , t : NoneTyp ) -> Type :
389
- if experiments . STRICT_OPTIONAL :
388
+ if state . strict_optional :
390
389
if isinstance (self .s , NoneTyp ) or (isinstance (self .s , Instance ) and
391
390
self .s .type .fullname () == 'builtins.object' ):
392
391
return t
@@ -400,7 +399,7 @@ def visit_uninhabited_type(self, t: UninhabitedType) -> Type:
400
399
401
400
def visit_deleted_type (self , t : DeletedType ) -> Type :
402
401
if isinstance (self .s , NoneTyp ):
403
- if experiments . STRICT_OPTIONAL :
402
+ if state . strict_optional :
404
403
return t
405
404
else :
406
405
return self .s
@@ -430,7 +429,7 @@ def visit_instance(self, t: Instance) -> Type:
430
429
args .append (self .meet (t .args [i ], si .args [i ]))
431
430
return Instance (t .type , args )
432
431
else :
433
- if experiments . STRICT_OPTIONAL :
432
+ if state . strict_optional :
434
433
return UninhabitedType ()
435
434
else :
436
435
return NoneTyp ()
@@ -441,7 +440,7 @@ def visit_instance(self, t: Instance) -> Type:
441
440
# See also above comment.
442
441
return self .s
443
442
else :
444
- if experiments . STRICT_OPTIONAL :
443
+ if state . strict_optional :
445
444
return UninhabitedType ()
446
445
else :
447
446
return NoneTyp ()
@@ -559,7 +558,7 @@ def default(self, typ: Type) -> Type:
559
558
if isinstance (typ , UnboundType ):
560
559
return AnyType (TypeOfAny .special_form )
561
560
else :
562
- if experiments . STRICT_OPTIONAL :
561
+ if state . strict_optional :
563
562
return UninhabitedType ()
564
563
else :
565
564
return NoneTyp ()
0 commit comments