Skip to content

Commit e97377c

Browse files
authored
Make all names and fullnames into properties (python#7829)
SymbolNode and FuncBase had name and fullname as methods while everything else has them as attributes or properties. Turn them into properties. Fixes python#7640. This was done with `sed -i -e 's/\.name()/.name/g' -e 's/\.fullname()/.fullname/g' mypy/*.py mypy/*/*.py mypyc/*.py mypyc/*/*.py misc/proper_plugin.py test-data/unit/plugins/*.py`.
1 parent d5fcc72 commit e97377c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+578
-554
lines changed

misc/proper_plugin.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,27 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:
4848
def is_special_target(right: ProperType) -> bool:
4949
"""Whitelist some special cases for use in isinstance() with improper types."""
5050
if isinstance(right, CallableType) and right.is_type_obj():
51-
if right.type_object().fullname() == 'builtins.tuple':
51+
if right.type_object().fullname == 'builtins.tuple':
5252
# Used with Union[Type, Tuple[Type, ...]].
5353
return True
54-
if right.type_object().fullname() in ('mypy.types.Type',
55-
'mypy.types.ProperType',
56-
'mypy.types.TypeAliasType'):
54+
if right.type_object().fullname in (
55+
'mypy.types.Type',
56+
'mypy.types.ProperType',
57+
'mypy.types.TypeAliasType'
58+
):
5759
# Special case: things like assert isinstance(typ, ProperType) are always OK.
5860
return True
59-
if right.type_object().fullname() in ('mypy.types.UnboundType',
60-
'mypy.types.TypeVarType',
61-
'mypy.types.RawExpressionType',
62-
'mypy.types.EllipsisType',
63-
'mypy.types.StarType',
64-
'mypy.types.TypeList',
65-
'mypy.types.CallableArgument',
66-
'mypy.types.PartialType',
67-
'mypy.types.ErasedType'):
61+
if right.type_object().fullname in (
62+
'mypy.types.UnboundType',
63+
'mypy.types.TypeVarType',
64+
'mypy.types.RawExpressionType',
65+
'mypy.types.EllipsisType',
66+
'mypy.types.StarType',
67+
'mypy.types.TypeList',
68+
'mypy.types.CallableArgument',
69+
'mypy.types.PartialType',
70+
'mypy.types.ErasedType'
71+
):
6872
# Special case: these are not valid targets for a type alias and thus safe.
6973
# TODO: introduce a SyntheticType base to simplify this?
7074
return True

mypy/argmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def expand_actual_type(self,
158158
actual_type = get_proper_type(actual_type)
159159
if actual_kind == nodes.ARG_STAR:
160160
if isinstance(actual_type, Instance):
161-
if actual_type.type.fullname() == 'builtins.list':
161+
if actual_type.type.fullname == 'builtins.list':
162162
# List *arg.
163163
return actual_type.args[0]
164164
elif actual_type.args:
@@ -187,7 +187,7 @@ def expand_actual_type(self,
187187
self.kwargs_used.add(formal_name)
188188
return actual_type.items[formal_name]
189189
elif (isinstance(actual_type, Instance)
190-
and (actual_type.type.fullname() == 'builtins.dict')):
190+
and (actual_type.type.fullname == 'builtins.dict')):
191191
# Dict **arg.
192192
# TODO: Handle arbitrary Mapping
193193
return actual_type.args[1]

mypy/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def all_imported_modules_in_file(self,
676676

677677
def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
678678
"""Function to correct for relative imports."""
679-
file_id = file.fullname()
679+
file_id = file.fullname
680680
rel = imp.relative
681681
if rel == 0:
682682
return imp.id
@@ -687,7 +687,7 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
687687
new_id = file_id + "." + imp.id if imp.id else file_id
688688

689689
if not new_id:
690-
self.errors.set_file(file.path, file.name())
690+
self.errors.set_file(file.path, file.name)
691691
self.errors.report(imp.line, 0,
692692
"No parent module -- cannot perform relative import",
693693
blocker=True)

mypy/checker.py

Lines changed: 69 additions & 67 deletions
Large diffs are not rendered by default.

mypy/checkexpr.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
230230
or lvalue)
231231
else:
232232
if isinstance(node, PlaceholderNode):
233-
assert False, 'PlaceholderNode %r leaked to checker' % node.fullname()
233+
assert False, 'PlaceholderNode %r leaked to checker' % node.fullname
234234
# Unknown reference; use any type implicitly to avoid
235235
# generating extra type errors.
236236
result = AnyType(TypeOfAny.from_error)
@@ -243,12 +243,12 @@ def analyze_var_ref(self, var: Var, context: Context) -> Type:
243243
if isinstance(var_type, Instance):
244244
if self.is_literal_context() and var_type.last_known_value is not None:
245245
return var_type.last_known_value
246-
if var.name() in {'True', 'False'}:
247-
return self.infer_literal_expr_type(var.name() == 'True', 'builtins.bool')
246+
if var.name in {'True', 'False'}:
247+
return self.infer_literal_expr_type(var.name == 'True', 'builtins.bool')
248248
return var.type
249249
else:
250250
if not var.is_ready and self.chk.in_checked_function():
251-
self.chk.handle_cannot_determine_type(var.name(), context)
251+
self.chk.handle_cannot_determine_type(var.name, context)
252252
# Implicit 'Any' type.
253253
return AnyType(TypeOfAny.special_form)
254254

@@ -328,7 +328,7 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
328328
if isinstance(e.callee.node, TypeAlias):
329329
target = get_proper_type(e.callee.node.target)
330330
if isinstance(target, Instance):
331-
fullname = target.type.fullname()
331+
fullname = target.type.fullname
332332
# * Call to a method on object that has a full name (see
333333
# method_fullname() for details on supported objects);
334334
# get_method_hook() and get_method_signature_hook() will
@@ -386,12 +386,12 @@ def method_fullname(self, object_type: Type, method_name: str) -> Optional[str]:
386386

387387
type_name = None
388388
if isinstance(object_type, Instance):
389-
type_name = object_type.type.fullname()
389+
type_name = object_type.type.fullname
390390
elif isinstance(object_type, (TypedDictType, LiteralType)):
391391
info = object_type.fallback.type.get_containing_type_info(method_name)
392-
type_name = info.fullname() if info is not None else None
392+
type_name = info.fullname if info is not None else None
393393
elif isinstance(object_type, TupleType):
394-
type_name = tuple_fallback(object_type).type.fullname()
394+
type_name = tuple_fallback(object_type).type.fullname
395395

396396
if type_name is not None:
397397
return '{}.{}'.format(type_name, method_name)
@@ -558,7 +558,7 @@ def try_infer_partial_type(self, e: CallExpr) -> None:
558558
partial_type.type is None):
559559
# A partial None type -> can't infer anything.
560560
return
561-
typename = partial_type.type.fullname()
561+
typename = partial_type.type.fullname
562562
methodname = e.callee.name
563563
# Sometimes we can infer a full type for a partial List, Dict or Set type.
564564
# TODO: Don't infer argument expression twice.
@@ -575,7 +575,7 @@ def try_infer_partial_type(self, e: CallExpr) -> None:
575575
and e.arg_kinds == [ARG_POS]):
576576
arg_type = get_proper_type(self.accept(e.args[0]))
577577
if isinstance(arg_type, Instance):
578-
arg_typename = arg_type.type.fullname()
578+
arg_typename = arg_type.type.fullname
579579
if arg_typename in self.container_args[typename][methodname]:
580580
full_item_types = [
581581
make_simplified_union([item_type, prev_type])
@@ -801,7 +801,7 @@ def check_call(self,
801801
is_super=False, is_operator=True, msg=self.msg,
802802
original_type=callee, chk=self.chk,
803803
in_literal_context=self.is_literal_context())
804-
callable_name = callee.type.fullname() + ".__call__"
804+
callable_name = callee.type.fullname + ".__call__"
805805
# Apply method signature hook, if one exists
806806
call_function = self.transform_callee_type(
807807
callable_name, call_function, args, arg_kinds, context, arg_names, callee)
@@ -840,7 +840,7 @@ def check_callable_call(self,
840840
callable_name = callee.name
841841
ret_type = get_proper_type(callee.ret_type)
842842
if callee.is_type_obj() and isinstance(ret_type, Instance):
843-
callable_name = ret_type.type.fullname()
843+
callable_name = ret_type.type.fullname
844844
if (isinstance(callable_node, RefExpr)
845845
and callable_node.fullname in ('enum.Enum', 'enum.IntEnum',
846846
'enum.Flag', 'enum.IntFlag')):
@@ -853,13 +853,13 @@ def check_callable_call(self,
853853
and not callee.type_object().fallback_to_any):
854854
type = callee.type_object()
855855
self.msg.cannot_instantiate_abstract_class(
856-
callee.type_object().name(), type.abstract_attributes,
856+
callee.type_object().name, type.abstract_attributes,
857857
context)
858858
elif (callee.is_type_obj() and callee.type_object().is_protocol
859859
# Exception for Type[...]
860860
and not callee.from_type_type):
861861
self.chk.fail(message_registry.CANNOT_INSTANTIATE_PROTOCOL
862-
.format(callee.type_object().name()), context)
862+
.format(callee.type_object().name), context)
863863

864864
formal_to_actual = map_actuals_to_formals(
865865
arg_kinds, arg_names,
@@ -935,7 +935,7 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type:
935935
return callee
936936
# We support Type of namedtuples but not of tuples in general
937937
if (isinstance(item, TupleType)
938-
and tuple_fallback(item).type.fullname() != 'builtins.tuple'):
938+
and tuple_fallback(item).type.fullname != 'builtins.tuple'):
939939
return self.analyze_type_type_callee(tuple_fallback(item), context)
940940

941941
self.msg.unsupported_type_type(item, context)
@@ -2180,8 +2180,8 @@ def dangerous_comparison(self, left: Type, right: Type,
21802180
return False
21812181
if isinstance(left, Instance) and isinstance(right, Instance):
21822182
# Special case some builtin implementations of AbstractSet.
2183-
if (left.type.fullname() in OVERLAPPING_TYPES_WHITELIST and
2184-
right.type.fullname() in OVERLAPPING_TYPES_WHITELIST):
2183+
if (left.type.fullname in OVERLAPPING_TYPES_WHITELIST and
2184+
right.type.fullname in OVERLAPPING_TYPES_WHITELIST):
21852185
abstract_set = self.chk.lookup_typeinfo('typing.AbstractSet')
21862186
left = map_instance_to_supertype(left, abstract_set)
21872187
right = map_instance_to_supertype(right, abstract_set)
@@ -2334,7 +2334,7 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]:
23342334
"""
23352335
for cls in typ.type.mro:
23362336
if cls.names.get(attr_name):
2337-
return cls.fullname()
2337+
return cls.fullname
23382338
return None
23392339

23402340
left_type = get_proper_type(left_type)
@@ -2899,7 +2899,7 @@ def visit_reveal_expr(self, expr: RevealExpr) -> Type:
28992899
# calculated at semantic analysis time. Use it to pull out the
29002900
# corresponding subset of variables in self.chk.type_map
29012901
names_to_types = {
2902-
var_node.name(): var_node.type for var_node in expr.local_nodes
2902+
var_node.name: var_node.type for var_node in expr.local_nodes
29032903
} if expr.local_nodes is not None else {}
29042904

29052905
self.msg.reveal_locals(names_to_types, expr)
@@ -2988,7 +2988,7 @@ class LongName(Generic[T]): ...
29882988
return self.apply_type_arguments_to_callable(tp, item.args, ctx)
29892989
elif (isinstance(item, TupleType) and
29902990
# Tuple[str, int]() fails at runtime, only named tuples and subclasses work.
2991-
tuple_fallback(item).type.fullname() != 'builtins.tuple'):
2991+
tuple_fallback(item).type.fullname != 'builtins.tuple'):
29922992
return type_object_type(tuple_fallback(item).type, self.named_type)
29932993
elif isinstance(item, AnyType):
29942994
return AnyType(TypeOfAny.from_another_any, source_any=item)
@@ -3793,7 +3793,7 @@ def visit_yield_from_expr(self, e: YieldFromExpr, allow_none_return: bool = Fals
37933793
# Determine the type of the entire yield from expression.
37943794
iter_type = get_proper_type(iter_type)
37953795
if (isinstance(iter_type, Instance) and
3796-
iter_type.type.fullname() == 'typing.Generator'):
3796+
iter_type.type.fullname == 'typing.Generator'):
37973797
expr_type = self.chk.get_generator_return_type(iter_type, False)
37983798
else:
37993799
# Non-Generators don't return anything from `yield from` expressions.
@@ -3906,7 +3906,7 @@ def visit_any(self, t: AnyType) -> bool:
39063906
def has_coroutine_decorator(t: Type) -> bool:
39073907
"""Whether t came from a function decorated with `@coroutine`."""
39083908
t = get_proper_type(t)
3909-
return isinstance(t, Instance) and t.type.fullname() == 'typing.AwaitableGenerator'
3909+
return isinstance(t, Instance) and t.type.fullname == 'typing.AwaitableGenerator'
39103910

39113911

39123912
def is_async_def(t: Type) -> bool:
@@ -3925,10 +3925,10 @@ def is_async_def(t: Type) -> bool:
39253925
# decorations.)
39263926
t = get_proper_type(t)
39273927
if (isinstance(t, Instance)
3928-
and t.type.fullname() == 'typing.AwaitableGenerator'
3928+
and t.type.fullname == 'typing.AwaitableGenerator'
39293929
and len(t.args) >= 4):
39303930
t = get_proper_type(t.args[3])
3931-
return isinstance(t, Instance) and t.type.fullname() == 'typing.Coroutine'
3931+
return isinstance(t, Instance) and t.type.fullname == 'typing.Coroutine'
39323932

39333933

39343934
def is_non_empty_tuple(t: Type) -> bool:
@@ -4025,7 +4025,7 @@ def arg_approximate_similarity(actual: Type, formal: Type) -> bool:
40254025
def is_typetype_like(typ: ProperType) -> bool:
40264026
return (isinstance(typ, TypeType)
40274027
or (isinstance(typ, FunctionLike) and typ.is_type_obj())
4028-
or (isinstance(typ, Instance) and typ.type.fullname() == "builtins.type"))
4028+
or (isinstance(typ, Instance) and typ.type.fullname == "builtins.type"))
40294029

40304030
if isinstance(formal, CallableType):
40314031
if isinstance(actual, (CallableType, Overloaded, TypeType)):
@@ -4205,7 +4205,7 @@ def custom_equality_method(typ: Type) -> bool:
42054205
method = typ.type.get('__eq__')
42064206
if method and isinstance(method.node, (SYMBOL_FUNCBASE_TYPES, Decorator, Var)):
42074207
if method.node.info:
4208-
return not method.node.info.fullname().startswith('builtins.')
4208+
return not method.node.info.fullname.startswith('builtins.')
42094209
return False
42104210
if isinstance(typ, UnionType):
42114211
return any(custom_equality_method(t) for t in typ.items)
@@ -4230,7 +4230,7 @@ def has_bytes_component(typ: Type, py2: bool = False) -> bool:
42304230
byte_types = {'builtins.bytes', 'builtins.bytearray'}
42314231
if isinstance(typ, UnionType):
42324232
return any(has_bytes_component(t) for t in typ.items)
4233-
if isinstance(typ, Instance) and typ.type.fullname() in byte_types:
4233+
if isinstance(typ, Instance) and typ.type.fullname in byte_types:
42344234
return True
42354235
return False
42364236

mypy/checkmember.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def analyze_instance_member_access(name: str,
180180
info = override_info
181181

182182
if (state.find_occurrences and
183-
info.name() == state.find_occurrences[0] and
183+
info.name == state.find_occurrences[0] and
184184
name == state.find_occurrences[1]):
185185
mx.msg.note("Occurrence of '{}.{}'".format(*state.find_occurrences), mx.context)
186186

@@ -375,7 +375,7 @@ def analyze_member_var_access(name: str,
375375
# __getattribute__ is defined on builtins.object and returns Any, so without
376376
# the guard this search will always find object.__getattribute__ and conclude
377377
# that the attribute exists
378-
if method and method.info.fullname() != 'builtins.object':
378+
if method and method.info.fullname != 'builtins.object':
379379
function = function_type(method, mx.builtin_type('builtins.function'))
380380
bound_method = bind_self(function, mx.self_type)
381381
typ = map_instance_to_supertype(itype, method.info)
@@ -384,15 +384,15 @@ def analyze_member_var_access(name: str,
384384
result = getattr_type.ret_type
385385

386386
# Call the attribute hook before returning.
387-
fullname = '{}.{}'.format(method.info.fullname(), name)
387+
fullname = '{}.{}'.format(method.info.fullname, name)
388388
hook = mx.chk.plugin.get_attribute_hook(fullname)
389389
if hook:
390390
result = hook(AttributeContext(get_proper_type(mx.original_type),
391391
result, mx.context, mx.chk))
392392
return result
393393
else:
394394
setattr_meth = info.get_method('__setattr__')
395-
if setattr_meth and setattr_meth.info.fullname() != 'builtins.object':
395+
if setattr_meth and setattr_meth.info.fullname != 'builtins.object':
396396
setattr_func = function_type(setattr_meth, mx.builtin_type('builtins.function'))
397397
bound_type = bind_self(setattr_func, mx.self_type)
398398
typ = map_instance_to_supertype(itype, setattr_meth.info)
@@ -566,10 +566,10 @@ def analyze_var(name: str,
566566
result = signature
567567
else:
568568
if not var.is_ready:
569-
mx.not_ready_callback(var.name(), mx.context)
569+
mx.not_ready_callback(var.name, mx.context)
570570
# Implicit 'Any' type.
571571
result = AnyType(TypeOfAny.special_form)
572-
fullname = '{}.{}'.format(var.info.fullname(), name)
572+
fullname = '{}.{}'.format(var.info.fullname, name)
573573
hook = mx.chk.plugin.get_attribute_hook(fullname)
574574
if result and not mx.is_lvalue and not implicit:
575575
result = analyze_descriptor_access(mx.original_type, result, mx.builtin_type,
@@ -682,7 +682,7 @@ def analyze_class_attribute_access(itype: Instance,
682682
# can't be accessed on the class object.
683683
if node.implicit and isinstance(node.node, Var) and node.node.is_final:
684684
mx.msg.fail(message_registry.CANNOT_ACCESS_FINAL_INSTANCE_ATTR
685-
.format(node.node.name()), mx.context)
685+
.format(node.node.name), mx.context)
686686

687687
# An assignment to final attribute on class object is also always an error,
688688
# independently of types.
@@ -757,7 +757,7 @@ def analyze_class_attribute_access(itype: Instance,
757757

758758
if isinstance(node.node, TypeVarExpr):
759759
mx.msg.fail(message_registry.CANNOT_USE_TYPEVAR_AS_EXPRESSION.format(
760-
info.name(), name), mx.context)
760+
info.name, name), mx.context)
761761
return AnyType(TypeOfAny.from_error)
762762

763763
if isinstance(node.node, TypeInfo):
@@ -878,7 +878,7 @@ def type_object_type(info: TypeInfo, builtin_type: Callable[[str], Instance]) ->
878878
method = new_method.node
879879
is_new = True
880880
else:
881-
if init_method.node.info.fullname() == 'builtins.object':
881+
if init_method.node.info.fullname == 'builtins.object':
882882
# Both are defined by object. But if we've got a bogus
883883
# base class, we can't know for sure, so check for that.
884884
if info.fallback_to_any:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy