Skip to content

Commit b6afa7f

Browse files
authored
Rename NoneTyp to NoneType (#6719)
Every other type gets an e in its name. Might as well fix this one. Keeps a NoneTyp alias to NoneType to avoid breaking external plugins.
1 parent 970a1b6 commit b6afa7f

38 files changed

+198
-190
lines changed

mypy/binder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if MYPY:
77
from typing import DefaultDict
88

9-
from mypy.types import Type, AnyType, PartialType, UnionType, TypeOfAny, NoneTyp
9+
from mypy.types import Type, AnyType, PartialType, UnionType, TypeOfAny, NoneType
1010
from mypy.subtypes import is_subtype
1111
from mypy.join import join_simple
1212
from mypy.sametypes import is_same_type
@@ -276,10 +276,10 @@ def assign_type(self, expr: Expression,
276276
# (See discussion in #3526)
277277
elif (isinstance(type, AnyType)
278278
and isinstance(declared_type, UnionType)
279-
and any(isinstance(item, NoneTyp) for item in declared_type.items)
280-
and isinstance(self.most_recent_enclosing_type(expr, NoneTyp()), NoneTyp)):
279+
and any(isinstance(item, NoneType) for item in declared_type.items)
280+
and isinstance(self.most_recent_enclosing_type(expr, NoneType()), NoneType)):
281281
# Replace any Nones in the union type with Any
282-
new_items = [type if isinstance(item, NoneTyp) else item
282+
new_items = [type if isinstance(item, NoneType) else item
283283
for item in declared_type.items]
284284
self.put(expr, UnionType(new_items))
285285
elif (isinstance(type, AnyType)

mypy/checker.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from mypy.typeanal import has_any_from_unimported_type, check_for_explicit_any
3131
from mypy.types import (
3232
Type, AnyType, CallableType, FunctionLike, Overloaded, TupleType, TypedDictType,
33-
Instance, NoneTyp, strip_type, TypeType, TypeOfAny,
33+
Instance, NoneType, strip_type, TypeType, TypeOfAny,
3434
UnionType, TypeVarId, TypeVarType, PartialType, DeletedType, UninhabitedType, TypeVarDef,
3535
true_only, false_only, function_type, is_named_instance, union_items, TypeQuery, LiteralType,
3636
is_optional, remove_optional
@@ -668,7 +668,7 @@ def get_generator_receive_type(self, return_type: Type, is_coroutine: bool) -> T
668668
else:
669669
# `return_type` is a supertype of Generator, so callers won't be able to send it
670670
# values. IOW, tc is None.
671-
return NoneTyp()
671+
return NoneType()
672672

673673
def get_coroutine_return_type(self, return_type: Type) -> Type:
674674
if isinstance(return_type, AnyType):
@@ -799,7 +799,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
799799
fdef = item
800800
# Check if __init__ has an invalid, non-None return type.
801801
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
803803
not self.dynamic_funcs[-1]):
804804
self.fail(message_registry.MUST_HAVE_NONE_RETURN_TYPE.format(fdef.name()),
805805
item)
@@ -845,7 +845,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
845845
if (self.options.python_version[0] == 2 and
846846
isinstance(typ.ret_type, Instance) and
847847
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)):
849849
self.fail(message_registry.INVALID_GENERATOR_RETURN_ITEM_TYPE, typ)
850850

851851
# 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])
944944
else:
945945
return_type = self.return_types[-1]
946946

947-
if (not isinstance(return_type, (NoneTyp, AnyType))
947+
if (not isinstance(return_type, (NoneType, AnyType))
948948
and not self.is_trivial_body(defn.body)):
949949
# Control flow fell off the end of a function that was
950950
# declared to return a non-None type and is not
@@ -1253,7 +1253,7 @@ def check_setattr_method(self, typ: Type, context: Context) -> None:
12531253
AnyType(TypeOfAny.special_form)],
12541254
[nodes.ARG_POS, nodes.ARG_POS, nodes.ARG_POS],
12551255
[None, None, None],
1256-
NoneTyp(),
1256+
NoneType(),
12571257
self.named_type('builtins.function'))
12581258
if not is_subtype(typ, method_type):
12591259
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
18121812
if isinstance(lvalue_type, PartialType) and lvalue_type.type is None:
18131813
# Try to infer a proper type for a variable with a partial None type.
18141814
rvalue_type = self.expr_checker.accept(rvalue)
1815-
if isinstance(rvalue_type, NoneTyp):
1815+
if isinstance(rvalue_type, NoneType):
18161816
# This doesn't actually provide any additional information -- multiple
18171817
# None initializers preserve the partial None type.
18181818
return
@@ -1823,7 +1823,7 @@ def check_assignment(self, lvalue: Lvalue, rvalue: Expression, infer_lvalue_type
18231823
if partial_types is not None:
18241824
if not self.current_node_deferred:
18251825
inferred_type = UnionType.make_simplified_union(
1826-
[rvalue_type, NoneTyp()])
1826+
[rvalue_type, NoneType()])
18271827
self.set_inferred_type(var, lvalue, inferred_type)
18281828
else:
18291829
var.type = None
@@ -2483,15 +2483,15 @@ def infer_variable_type(self, name: Var, lvalue: Lvalue,
24832483
self.set_inferred_type(name, lvalue, init_type)
24842484

24852485
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):
24872487
partial_type = PartialType(None, name, [init_type])
24882488
elif isinstance(init_type, Instance):
24892489
fullname = init_type.type.fullname()
24902490
if (isinstance(lvalue, (NameExpr, MemberExpr)) and
24912491
(fullname == 'builtins.list' or
24922492
fullname == 'builtins.set' or
24932493
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)):
24952495
partial_type = PartialType(init_type.type, name, init_type.args)
24962496
else:
24972497
return False
@@ -2643,7 +2643,7 @@ def check_indexed_assignment(self, lvalue: IndexExpr,
26432643
arg_types=[self.named_type('builtins.str'), item_type],
26442644
arg_kinds=[ARG_POS, ARG_POS],
26452645
arg_names=[None, None],
2646-
ret_type=NoneTyp(),
2646+
ret_type=NoneType(),
26472647
fallback=self.named_type('builtins.function')
26482648
) # type: Type
26492649
else:
@@ -2707,7 +2707,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
27072707

27082708
if s.expr:
27092709
is_lambda = isinstance(self.scope.top_function(), LambdaExpr)
2710-
declared_none_return = isinstance(return_type, NoneTyp)
2710+
declared_none_return = isinstance(return_type, NoneType)
27112711
declared_any_return = isinstance(return_type, AnyType)
27122712

27132713
# This controls whether or not we allow a function call that
@@ -2742,7 +2742,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
27422742
if declared_none_return:
27432743
# Lambdas are allowed to have None returns.
27442744
# 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):
27462746
return
27472747
self.fail(message_registry.NO_RETURN_VALUE_EXPECTED, s)
27482748
else:
@@ -2760,7 +2760,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
27602760
isinstance(return_type, AnyType)):
27612761
return
27622762

2763-
if isinstance(return_type, (NoneTyp, AnyType)):
2763+
if isinstance(return_type, (NoneType, AnyType)):
27642764
return
27652765

27662766
if self.in_checked_function():
@@ -2870,7 +2870,7 @@ def type_check_raise(self, e: Expression, s: RaiseStmt,
28702870
return
28712871
expected_type = self.named_type('builtins.BaseException') # type: Type
28722872
if optional:
2873-
expected_type = UnionType([expected_type, NoneTyp()])
2873+
expected_type = UnionType([expected_type, NoneType()])
28742874
self.check_subtype(typ, expected_type, s, message_registry.INVALID_EXCEPTION)
28752875

28762876
def visit_try_stmt(self, s: TryStmt) -> None:
@@ -3191,7 +3191,7 @@ def visit_print_stmt(self, s: PrintStmt) -> None:
31913191
self.expr_checker.accept(arg)
31923192
if s.target:
31933193
target_type = self.expr_checker.accept(s.target)
3194-
if not isinstance(target_type, NoneTyp):
3194+
if not isinstance(target_type, NoneType):
31953195
# TODO: Also verify the type of 'write'.
31963196
self.expr_checker.analyze_external_member_access('write', target_type, s.target)
31973197

@@ -3435,7 +3435,7 @@ def find_isinstance_check(self, node: Expression
34353435
# two elements in node.operands, and at least one of them
34363436
# should represent a None.
34373437
vartype = type_map[expr]
3438-
none_typ = [TypeRange(NoneTyp(), is_upper_bound=False)]
3438+
none_typ = [TypeRange(NoneType(), is_upper_bound=False)]
34393439
if_vars, else_vars = conditional_type_map(expr, vartype, none_typ)
34403440
break
34413441

@@ -3549,7 +3549,7 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
35493549

35503550
def contains_none(self, t: Type) -> bool:
35513551
return (
3552-
isinstance(t, NoneTyp) or
3552+
isinstance(t, NoneType) or
35533553
(isinstance(t, UnionType) and any(self.contains_none(ut) for ut in t.items)) or
35543554
(isinstance(t, TupleType) and any(self.contains_none(tt) for tt in t.items)) or
35553555
(isinstance(t, Instance) and bool(t.args)
@@ -3687,7 +3687,7 @@ def enter_partial_types(self, *, is_function: bool = False,
36873687
and isinstance(var.type, PartialType)
36883688
and var.type.type is None
36893689
and not permissive):
3690-
var.type = NoneTyp()
3690+
var.type = NoneType()
36913691
else:
36923692
if var not in self.partial_reported and not permissive:
36933693
self.msg.need_annotation_for_var(var, context)
@@ -3706,7 +3706,7 @@ def handle_partial_var_type(
37063706
# 'None' partial type. It has a well-defined type. In an lvalue context
37073707
# we want to preserve the knowledge of it being a partial type.
37083708
if not is_lvalue:
3709-
return NoneTyp()
3709+
return NoneType()
37103710
else:
37113711
return typ
37123712
else:
@@ -3729,7 +3729,7 @@ def fixup_partial_type(self, typ: Type) -> Type:
37293729
if not isinstance(typ, PartialType):
37303730
return typ
37313731
if typ.type is None:
3732-
return UnionType.make_union([AnyType(TypeOfAny.unannotated), NoneTyp()])
3732+
return UnionType.make_union([AnyType(TypeOfAny.unannotated), NoneType()])
37333733
else:
37343734
return Instance(
37353735
typ.type,
@@ -4227,8 +4227,8 @@ def is_valid_inferred_type(typ: Type) -> bool:
42274227
invalid. When doing strict Optional checking, only None and types that are
42284228
incompletely defined (i.e. contain UninhabitedType) are invalid.
42294229
"""
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
42324232
# the initializer is None, but we only do that if we can't infer a
42334233
# specific Optional type. This resolution happens in
42344234
# leave_partial_types when we pop a partial types scope.

mypy/checkexpr.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
has_any_from_unimported_type, check_for_explicit_any, set_any_tvars, expand_type_alias
1717
)
1818
from mypy.types import (
19-
Type, AnyType, CallableType, Overloaded, NoneTyp, TypeVarDef,
19+
Type, AnyType, CallableType, Overloaded, NoneType, TypeVarDef,
2020
TupleType, TypedDictType, Instance, TypeVarType, ErasedType, UnionType,
2121
PartialType, DeletedType, UninhabitedType, TypeType, TypeOfAny, LiteralType, LiteralValue,
2222
true_only, false_only, is_named_instance, function_type, callable_type, FunctionLike,
@@ -325,7 +325,7 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
325325
# Warn on calls to functions that always return None. The check
326326
# of ret_type is both a common-case optimization and prevents reporting
327327
# the error in dynamic functions (where it will be Any).
328-
if (not allow_none_return and isinstance(ret_type, NoneTyp)
328+
if (not allow_none_return and isinstance(ret_type, NoneType)
329329
and self.always_returns_none(e.callee)):
330330
self.chk.msg.does_not_return_value(callee_type, e)
331331
return AnyType(TypeOfAny.from_error)
@@ -378,13 +378,13 @@ def defn_returns_none(self, defn: Optional[SymbolNode]) -> bool:
378378
"""Check if `defn` can _only_ return None."""
379379
if isinstance(defn, FuncDef):
380380
return (isinstance(defn.type, CallableType) and
381-
isinstance(defn.type.ret_type, NoneTyp))
381+
isinstance(defn.type.ret_type, NoneType))
382382
if isinstance(defn, OverloadedFuncDef):
383383
return all(isinstance(item.type, CallableType) and
384-
isinstance(item.type.ret_type, NoneTyp) for item in defn.items)
384+
isinstance(item.type.ret_type, NoneType) for item in defn.items)
385385
if isinstance(defn, Var):
386386
if (not defn.is_inferred and isinstance(defn.type, CallableType) and
387-
isinstance(defn.type.ret_type, NoneTyp)):
387+
isinstance(defn.type.ret_type, NoneType)):
388388
return True
389389
if isinstance(defn.type, Instance):
390390
sym = defn.type.type.get('__call__')
@@ -854,7 +854,7 @@ def infer_arg_types_in_empty_context(self, args: List[Expression]) -> List[Type]
854854
for arg in args:
855855
arg_type = self.accept(arg)
856856
if has_erased_component(arg_type):
857-
res.append(NoneTyp())
857+
res.append(NoneType())
858858
else:
859859
res.append(arg_type)
860860
return res
@@ -1010,7 +1010,7 @@ def infer_function_type_arguments(self, callee_type: CallableType,
10101010
# correspondence with dict type variables. This is a marginal issue and
10111011
# a little tricky to fix so it's left unfixed for now.
10121012
first_arg = inferred_args[0]
1013-
if isinstance(first_arg, (NoneTyp, UninhabitedType)):
1013+
if isinstance(first_arg, (NoneType, UninhabitedType)):
10141014
inferred_args[0] = self.named_type('builtins.str')
10151015
elif not first_arg or not is_subtype(self.named_type('builtins.str'), first_arg):
10161016
self.msg.fail(message_registry.KEYWORD_ARGUMENT_REQUIRES_STR_KEY_TYPE,
@@ -1045,7 +1045,7 @@ def infer_function_type_arguments_pass2(
10451045
# that they are not applied yet below.
10461046
inferred_args = list(old_inferred_args)
10471047
for i, arg in enumerate(inferred_args):
1048-
if isinstance(arg, (NoneTyp, UninhabitedType)) or has_erased_component(arg):
1048+
if isinstance(arg, (NoneType, UninhabitedType)) or has_erased_component(arg):
10491049
inferred_args[i] = None
10501050
callee_type = self.apply_generic_arguments(callee_type, inferred_args, context)
10511051

@@ -1991,7 +1991,7 @@ def dangerous_comparison(self, left: Type, right: Type) -> bool:
19911991
"""
19921992
if not self.chk.options.strict_equality:
19931993
return False
1994-
if isinstance(left, NoneTyp) or isinstance(right, NoneTyp):
1994+
if isinstance(left, NoneType) or isinstance(right, NoneType):
19951995
return False
19961996
if isinstance(left, UnionType) and isinstance(right, UnionType):
19971997
left = remove_optional(left)
@@ -2602,7 +2602,7 @@ def visit_reveal_expr(self, expr: RevealExpr) -> Type:
26022602
} if expr.local_nodes is not None else {}
26032603

26042604
self.msg.reveal_locals(names_to_types, expr)
2605-
return NoneTyp()
2605+
return NoneType()
26062606

26072607
def visit_type_application(self, tapp: TypeApplication) -> Type:
26082608
"""Type check a type application (expr[type, ...]).
@@ -2915,7 +2915,7 @@ def visit_lambda_expr(self, e: LambdaExpr) -> Type:
29152915
if e.expr() not in self.chk.type_map:
29162916
self.accept(e.expr(), allow_none_return=True)
29172917
ret_type = self.chk.type_map[e.expr()]
2918-
if isinstance(ret_type, NoneTyp):
2918+
if isinstance(ret_type, NoneType):
29192919
# For "lambda ...: None", just use type from the context.
29202920
# Important when the context is Callable[..., None] which
29212921
# really means Void. See #1425.
@@ -3102,11 +3102,11 @@ def visit_generator_expr(self, e: GeneratorExpr) -> Type:
31023102
if any(e.is_async):
31033103
typ = 'typing.AsyncGenerator'
31043104
# received type is always None in async generator expressions
3105-
additional_args = [NoneTyp()] # type: List[Type]
3105+
additional_args = [NoneType()] # type: List[Type]
31063106
else:
31073107
typ = 'typing.Generator'
31083108
# received type and returned type are None
3109-
additional_args = [NoneTyp(), NoneTyp()]
3109+
additional_args = [NoneType(), NoneType()]
31103110
return self.check_generator_or_comprehension(e, typ, '<generator>',
31113111
additional_args=additional_args)
31123112

@@ -3357,7 +3357,7 @@ def visit_yield_expr(self, e: YieldExpr) -> Type:
33573357
return_type = self.chk.return_types[-1]
33583358
expected_item_type = self.chk.get_generator_yield_type(return_type, False)
33593359
if e.expr is None:
3360-
if (not isinstance(expected_item_type, (NoneTyp, AnyType))
3360+
if (not isinstance(expected_item_type, (NoneType, AnyType))
33613361
and self.chk.in_checked_function()):
33623362
self.chk.fail(message_registry.YIELD_VALUE_EXPECTED, e)
33633363
else:
@@ -3443,9 +3443,9 @@ def visit_yield_from_expr(self, e: YieldFromExpr, allow_none_return: bool = Fals
34433443
expr_type = AnyType(TypeOfAny.from_another_any, source_any=actual_item_type)
34443444
else:
34453445
# Treat `Iterator[X]` as a shorthand for `Generator[X, None, Any]`.
3446-
expr_type = NoneTyp()
3446+
expr_type = NoneType()
34473447

3448-
if not allow_none_return and isinstance(expr_type, NoneTyp):
3448+
if not allow_none_return and isinstance(expr_type, NoneType):
34493449
self.chk.msg.does_not_return_value(None, e)
34503450
return expr_type
34513451

0 commit comments

Comments
 (0)