30
30
from mypy .typeanal import has_any_from_unimported_type , check_for_explicit_any
31
31
from mypy .types import (
32
32
Type , AnyType , CallableType , FunctionLike , Overloaded , TupleType , TypedDictType ,
33
- Instance , NoneTyp , strip_type , TypeType , TypeOfAny ,
33
+ Instance , NoneType , strip_type , TypeType , TypeOfAny ,
34
34
UnionType , TypeVarId , TypeVarType , PartialType , DeletedType , UninhabitedType , TypeVarDef ,
35
35
true_only , false_only , function_type , is_named_instance , union_items , TypeQuery , LiteralType ,
36
36
is_optional , remove_optional
@@ -668,7 +668,7 @@ def get_generator_receive_type(self, return_type: Type, is_coroutine: bool) -> T
668
668
else :
669
669
# `return_type` is a supertype of Generator, so callers won't be able to send it
670
670
# values. IOW, tc is None.
671
- return NoneTyp ()
671
+ return NoneType ()
672
672
673
673
def get_coroutine_return_type (self , return_type : Type ) -> Type :
674
674
if isinstance (return_type , AnyType ):
@@ -799,7 +799,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
799
799
fdef = item
800
800
# Check if __init__ has an invalid, non-None return type.
801
801
if (fdef .info and fdef .name () in ('__init__' , '__init_subclass__' ) and
802
- not isinstance (typ .ret_type , NoneTyp ) and
802
+ not isinstance (typ .ret_type , NoneType ) and
803
803
not self .dynamic_funcs [- 1 ]):
804
804
self .fail (message_registry .MUST_HAVE_NONE_RETURN_TYPE .format (fdef .name ()),
805
805
item )
@@ -845,7 +845,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
845
845
if (self .options .python_version [0 ] == 2 and
846
846
isinstance (typ .ret_type , Instance ) and
847
847
typ .ret_type .type .fullname () == 'typing.Generator' ):
848
- if not isinstance (typ .ret_type .args [2 ], (NoneTyp , AnyType )):
848
+ if not isinstance (typ .ret_type .args [2 ], (NoneType , AnyType )):
849
849
self .fail (message_registry .INVALID_GENERATOR_RETURN_ITEM_TYPE , typ )
850
850
851
851
# Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`.
@@ -944,7 +944,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
944
944
else :
945
945
return_type = self .return_types [- 1 ]
946
946
947
- if (not isinstance (return_type , (NoneTyp , AnyType ))
947
+ if (not isinstance (return_type , (NoneType , AnyType ))
948
948
and not self .is_trivial_body (defn .body )):
949
949
# Control flow fell off the end of a function that was
950
950
# declared to return a non-None type and is not
@@ -1253,7 +1253,7 @@ def check_setattr_method(self, typ: Type, context: Context) -> None:
1253
1253
AnyType (TypeOfAny .special_form )],
1254
1254
[nodes .ARG_POS , nodes .ARG_POS , nodes .ARG_POS ],
1255
1255
[None , None , None ],
1256
- NoneTyp (),
1256
+ NoneType (),
1257
1257
self .named_type ('builtins.function' ))
1258
1258
if not is_subtype (typ , method_type ):
1259
1259
self .msg .invalid_signature_for_special_method (typ , context , '__setattr__' )
@@ -1812,7 +1812,7 @@ def check_assignment(self, lvalue: Lvalue, rvalue: Expression, infer_lvalue_type
1812
1812
if isinstance (lvalue_type , PartialType ) and lvalue_type .type is None :
1813
1813
# Try to infer a proper type for a variable with a partial None type.
1814
1814
rvalue_type = self .expr_checker .accept (rvalue )
1815
- if isinstance (rvalue_type , NoneTyp ):
1815
+ if isinstance (rvalue_type , NoneType ):
1816
1816
# This doesn't actually provide any additional information -- multiple
1817
1817
# None initializers preserve the partial None type.
1818
1818
return
@@ -1823,7 +1823,7 @@ def check_assignment(self, lvalue: Lvalue, rvalue: Expression, infer_lvalue_type
1823
1823
if partial_types is not None :
1824
1824
if not self .current_node_deferred :
1825
1825
inferred_type = UnionType .make_simplified_union (
1826
- [rvalue_type , NoneTyp ()])
1826
+ [rvalue_type , NoneType ()])
1827
1827
self .set_inferred_type (var , lvalue , inferred_type )
1828
1828
else :
1829
1829
var .type = None
@@ -2483,15 +2483,15 @@ def infer_variable_type(self, name: Var, lvalue: Lvalue,
2483
2483
self .set_inferred_type (name , lvalue , init_type )
2484
2484
2485
2485
def infer_partial_type (self , name : Var , lvalue : Lvalue , init_type : Type ) -> bool :
2486
- if isinstance (init_type , NoneTyp ):
2486
+ if isinstance (init_type , NoneType ):
2487
2487
partial_type = PartialType (None , name , [init_type ])
2488
2488
elif isinstance (init_type , Instance ):
2489
2489
fullname = init_type .type .fullname ()
2490
2490
if (isinstance (lvalue , (NameExpr , MemberExpr )) and
2491
2491
(fullname == 'builtins.list' or
2492
2492
fullname == 'builtins.set' or
2493
2493
fullname == 'builtins.dict' ) and
2494
- all (isinstance (t , (NoneTyp , UninhabitedType )) for t in init_type .args )):
2494
+ all (isinstance (t , (NoneType , UninhabitedType )) for t in init_type .args )):
2495
2495
partial_type = PartialType (init_type .type , name , init_type .args )
2496
2496
else :
2497
2497
return False
@@ -2643,7 +2643,7 @@ def check_indexed_assignment(self, lvalue: IndexExpr,
2643
2643
arg_types = [self .named_type ('builtins.str' ), item_type ],
2644
2644
arg_kinds = [ARG_POS , ARG_POS ],
2645
2645
arg_names = [None , None ],
2646
- ret_type = NoneTyp (),
2646
+ ret_type = NoneType (),
2647
2647
fallback = self .named_type ('builtins.function' )
2648
2648
) # type: Type
2649
2649
else :
@@ -2707,7 +2707,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
2707
2707
2708
2708
if s .expr :
2709
2709
is_lambda = isinstance (self .scope .top_function (), LambdaExpr )
2710
- declared_none_return = isinstance (return_type , NoneTyp )
2710
+ declared_none_return = isinstance (return_type , NoneType )
2711
2711
declared_any_return = isinstance (return_type , AnyType )
2712
2712
2713
2713
# This controls whether or not we allow a function call that
@@ -2742,7 +2742,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
2742
2742
if declared_none_return :
2743
2743
# Lambdas are allowed to have None returns.
2744
2744
# Functions returning a value of type None are allowed to have a None return.
2745
- if is_lambda or isinstance (typ , NoneTyp ):
2745
+ if is_lambda or isinstance (typ , NoneType ):
2746
2746
return
2747
2747
self .fail (message_registry .NO_RETURN_VALUE_EXPECTED , s )
2748
2748
else :
@@ -2760,7 +2760,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
2760
2760
isinstance (return_type , AnyType )):
2761
2761
return
2762
2762
2763
- if isinstance (return_type , (NoneTyp , AnyType )):
2763
+ if isinstance (return_type , (NoneType , AnyType )):
2764
2764
return
2765
2765
2766
2766
if self .in_checked_function ():
@@ -2870,7 +2870,7 @@ def type_check_raise(self, e: Expression, s: RaiseStmt,
2870
2870
return
2871
2871
expected_type = self .named_type ('builtins.BaseException' ) # type: Type
2872
2872
if optional :
2873
- expected_type = UnionType ([expected_type , NoneTyp ()])
2873
+ expected_type = UnionType ([expected_type , NoneType ()])
2874
2874
self .check_subtype (typ , expected_type , s , message_registry .INVALID_EXCEPTION )
2875
2875
2876
2876
def visit_try_stmt (self , s : TryStmt ) -> None :
@@ -3191,7 +3191,7 @@ def visit_print_stmt(self, s: PrintStmt) -> None:
3191
3191
self .expr_checker .accept (arg )
3192
3192
if s .target :
3193
3193
target_type = self .expr_checker .accept (s .target )
3194
- if not isinstance (target_type , NoneTyp ):
3194
+ if not isinstance (target_type , NoneType ):
3195
3195
# TODO: Also verify the type of 'write'.
3196
3196
self .expr_checker .analyze_external_member_access ('write' , target_type , s .target )
3197
3197
@@ -3435,7 +3435,7 @@ def find_isinstance_check(self, node: Expression
3435
3435
# two elements in node.operands, and at least one of them
3436
3436
# should represent a None.
3437
3437
vartype = type_map [expr ]
3438
- none_typ = [TypeRange (NoneTyp (), is_upper_bound = False )]
3438
+ none_typ = [TypeRange (NoneType (), is_upper_bound = False )]
3439
3439
if_vars , else_vars = conditional_type_map (expr , vartype , none_typ )
3440
3440
break
3441
3441
@@ -3549,7 +3549,7 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
3549
3549
3550
3550
def contains_none (self , t : Type ) -> bool :
3551
3551
return (
3552
- isinstance (t , NoneTyp ) or
3552
+ isinstance (t , NoneType ) or
3553
3553
(isinstance (t , UnionType ) and any (self .contains_none (ut ) for ut in t .items )) or
3554
3554
(isinstance (t , TupleType ) and any (self .contains_none (tt ) for tt in t .items )) or
3555
3555
(isinstance (t , Instance ) and bool (t .args )
@@ -3687,7 +3687,7 @@ def enter_partial_types(self, *, is_function: bool = False,
3687
3687
and isinstance (var .type , PartialType )
3688
3688
and var .type .type is None
3689
3689
and not permissive ):
3690
- var .type = NoneTyp ()
3690
+ var .type = NoneType ()
3691
3691
else :
3692
3692
if var not in self .partial_reported and not permissive :
3693
3693
self .msg .need_annotation_for_var (var , context )
@@ -3706,7 +3706,7 @@ def handle_partial_var_type(
3706
3706
# 'None' partial type. It has a well-defined type. In an lvalue context
3707
3707
# we want to preserve the knowledge of it being a partial type.
3708
3708
if not is_lvalue :
3709
- return NoneTyp ()
3709
+ return NoneType ()
3710
3710
else :
3711
3711
return typ
3712
3712
else :
@@ -3729,7 +3729,7 @@ def fixup_partial_type(self, typ: Type) -> Type:
3729
3729
if not isinstance (typ , PartialType ):
3730
3730
return typ
3731
3731
if typ .type is None :
3732
- return UnionType .make_union ([AnyType (TypeOfAny .unannotated ), NoneTyp ()])
3732
+ return UnionType .make_union ([AnyType (TypeOfAny .unannotated ), NoneType ()])
3733
3733
else :
3734
3734
return Instance (
3735
3735
typ .type ,
@@ -4227,8 +4227,8 @@ def is_valid_inferred_type(typ: Type) -> bool:
4227
4227
invalid. When doing strict Optional checking, only None and types that are
4228
4228
incompletely defined (i.e. contain UninhabitedType) are invalid.
4229
4229
"""
4230
- if isinstance (typ , (NoneTyp , UninhabitedType )):
4231
- # With strict Optional checking, we *may* eventually infer NoneTyp when
4230
+ if isinstance (typ , (NoneType , UninhabitedType )):
4231
+ # With strict Optional checking, we *may* eventually infer NoneType when
4232
4232
# the initializer is None, but we only do that if we can't infer a
4233
4233
# specific Optional type. This resolution happens in
4234
4234
# leave_partial_types when we pop a partial types scope.
0 commit comments