Skip to content

Commit 8b1d5f3

Browse files
committed
Fix all calls to name and fullname functions
`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 fc6495d commit 8b1d5f3

Some content is hidden

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

60 files changed

+530
-530
lines changed

misc/proper_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ 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',
54+
if right.type_object().fullname in ('mypy.types.Type',
5555
'mypy.types.ProperType',
5656
'mypy.types.TypeAliasType'):
5757
# Special case: things like assert isinstance(typ, ProperType) are always OK.
5858
return True
59-
if right.type_object().fullname() in ('mypy.types.UnboundType',
59+
if right.type_object().fullname in ('mypy.types.UnboundType',
6060
'mypy.types.TypeVarType',
6161
'mypy.types.RawExpressionType',
6262
'mypy.types.EllipsisType',

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
@@ -649,7 +649,7 @@ def all_imported_modules_in_file(self,
649649

650650
def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
651651
"""Function to correct for relative imports."""
652-
file_id = file.fullname()
652+
file_id = file.fullname
653653
rel = imp.relative
654654
if rel == 0:
655655
return imp.id
@@ -660,7 +660,7 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
660660
new_id = file_id + "." + imp.id if imp.id else file_id
661661

662662
if not new_id:
663-
self.errors.set_file(file.path, file.name())
663+
self.errors.set_file(file.path, file.name)
664664
self.errors.report(imp.line, 0,
665665
"No parent module -- cannot perform relative import",
666666
blocker=True)

mypy/checker.py

Lines changed: 67 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,
@@ -929,7 +929,7 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Proper
929929
return callee
930930
# We support Type of namedtuples but not of tuples in general
931931
if (isinstance(item, TupleType)
932-
and tuple_fallback(item).type.fullname() != 'builtins.tuple'):
932+
and tuple_fallback(item).type.fullname != 'builtins.tuple'):
933933
return self.analyze_type_type_callee(tuple_fallback(item), context)
934934

935935
self.msg.unsupported_type_type(item, context)
@@ -2173,8 +2173,8 @@ def dangerous_comparison(self, left: Type, right: Type,
21732173
return False
21742174
if isinstance(left, Instance) and isinstance(right, Instance):
21752175
# Special case some builtin implementations of AbstractSet.
2176-
if (left.type.fullname() in OVERLAPPING_TYPES_WHITELIST and
2177-
right.type.fullname() in OVERLAPPING_TYPES_WHITELIST):
2176+
if (left.type.fullname in OVERLAPPING_TYPES_WHITELIST and
2177+
right.type.fullname in OVERLAPPING_TYPES_WHITELIST):
21782178
abstract_set = self.chk.lookup_typeinfo('typing.AbstractSet')
21792179
left = map_instance_to_supertype(left, abstract_set)
21802180
right = map_instance_to_supertype(right, abstract_set)
@@ -2327,7 +2327,7 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]:
23272327
"""
23282328
for cls in typ.type.mro:
23292329
if cls.names.get(attr_name):
2330-
return cls.fullname()
2330+
return cls.fullname
23312331
return None
23322332

23332333
left_type = get_proper_type(left_type)
@@ -2889,7 +2889,7 @@ def visit_reveal_expr(self, expr: RevealExpr) -> Type:
28892889
# calculated at semantic analysis time. Use it to pull out the
28902890
# corresponding subset of variables in self.chk.type_map
28912891
names_to_types = {
2892-
var_node.name(): var_node.type for var_node in expr.local_nodes
2892+
var_node.name: var_node.type for var_node in expr.local_nodes
28932893
} if expr.local_nodes is not None else {}
28942894

28952895
self.msg.reveal_locals(names_to_types, expr)
@@ -2978,7 +2978,7 @@ class LongName(Generic[T]): ...
29782978
return self.apply_type_arguments_to_callable(tp, item.args, ctx)
29792979
elif (isinstance(item, TupleType) and
29802980
# Tuple[str, int]() fails at runtime, only named tuples and subclasses work.
2981-
tuple_fallback(item).type.fullname() != 'builtins.tuple'):
2981+
tuple_fallback(item).type.fullname != 'builtins.tuple'):
29822982
return type_object_type(tuple_fallback(item).type, self.named_type)
29832983
elif isinstance(item, AnyType):
29842984
return AnyType(TypeOfAny.from_another_any, source_any=item)
@@ -3780,7 +3780,7 @@ def visit_yield_from_expr(self, e: YieldFromExpr, allow_none_return: bool = Fals
37803780
# Determine the type of the entire yield from expression.
37813781
iter_type = get_proper_type(iter_type)
37823782
if (isinstance(iter_type, Instance) and
3783-
iter_type.type.fullname() == 'typing.Generator'):
3783+
iter_type.type.fullname == 'typing.Generator'):
37843784
expr_type = self.chk.get_generator_return_type(iter_type, False)
37853785
else:
37863786
# Non-Generators don't return anything from `yield from` expressions.
@@ -3893,7 +3893,7 @@ def visit_any(self, t: AnyType) -> bool:
38933893
def has_coroutine_decorator(t: Type) -> bool:
38943894
"""Whether t came from a function decorated with `@coroutine`."""
38953895
t = get_proper_type(t)
3896-
return isinstance(t, Instance) and t.type.fullname() == 'typing.AwaitableGenerator'
3896+
return isinstance(t, Instance) and t.type.fullname == 'typing.AwaitableGenerator'
38973897

38983898

38993899
def is_async_def(t: Type) -> bool:
@@ -3912,10 +3912,10 @@ def is_async_def(t: Type) -> bool:
39123912
# decorations.)
39133913
t = get_proper_type(t)
39143914
if (isinstance(t, Instance)
3915-
and t.type.fullname() == 'typing.AwaitableGenerator'
3915+
and t.type.fullname == 'typing.AwaitableGenerator'
39163916
and len(t.args) >= 4):
39173917
t = get_proper_type(t.args[3])
3918-
return isinstance(t, Instance) and t.type.fullname() == 'typing.Coroutine'
3918+
return isinstance(t, Instance) and t.type.fullname == 'typing.Coroutine'
39193919

39203920

39213921
def is_non_empty_tuple(t: Type) -> bool:
@@ -4012,7 +4012,7 @@ def arg_approximate_similarity(actual: Type, formal: Type) -> bool:
40124012
def is_typetype_like(typ: ProperType) -> bool:
40134013
return (isinstance(typ, TypeType)
40144014
or (isinstance(typ, FunctionLike) and typ.is_type_obj())
4015-
or (isinstance(typ, Instance) and typ.type.fullname() == "builtins.type"))
4015+
or (isinstance(typ, Instance) and typ.type.fullname == "builtins.type"))
40164016

40174017
if isinstance(formal, CallableType):
40184018
if isinstance(actual, (CallableType, Overloaded, TypeType)):
@@ -4192,7 +4192,7 @@ def custom_equality_method(typ: Type) -> bool:
41924192
method = typ.type.get('__eq__')
41934193
if method and isinstance(method.node, (SYMBOL_FUNCBASE_TYPES, Decorator, Var)):
41944194
if method.node.info:
4195-
return not method.node.info.fullname().startswith('builtins.')
4195+
return not method.node.info.fullname.startswith('builtins.')
41964196
return False
41974197
if isinstance(typ, UnionType):
41984198
return any(custom_equality_method(t) for t in typ.items)
@@ -4217,7 +4217,7 @@ def has_bytes_component(typ: Type, py2: bool = False) -> bool:
42174217
byte_types = {'builtins.bytes', 'builtins.bytearray'}
42184218
if isinstance(typ, UnionType):
42194219
return any(has_bytes_component(t) for t in typ.items)
4220-
if isinstance(typ, Instance) and typ.type.fullname() in byte_types:
4220+
if isinstance(typ, Instance) and typ.type.fullname in byte_types:
42214221
return True
42224222
return False
42234223

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

@@ -367,7 +367,7 @@ def analyze_member_var_access(name: str,
367367
# __getattribute__ is defined on builtins.object and returns Any, so without
368368
# the guard this search will always find object.__getattribute__ and conclude
369369
# that the attribute exists
370-
if method and method.info.fullname() != 'builtins.object':
370+
if method and method.info.fullname != 'builtins.object':
371371
function = function_type(method, mx.builtin_type('builtins.function'))
372372
bound_method = bind_self(function, mx.self_type)
373373
typ = map_instance_to_supertype(itype, method.info)
@@ -376,15 +376,15 @@ def analyze_member_var_access(name: str,
376376
result = getattr_type.ret_type
377377

378378
# Call the attribute hook before returning.
379-
fullname = '{}.{}'.format(method.info.fullname(), name)
379+
fullname = '{}.{}'.format(method.info.fullname, name)
380380
hook = mx.chk.plugin.get_attribute_hook(fullname)
381381
if hook:
382382
result = hook(AttributeContext(get_proper_type(mx.original_type),
383383
result, mx.context, mx.chk))
384384
return result
385385
else:
386386
setattr_meth = info.get_method('__setattr__')
387-
if setattr_meth and setattr_meth.info.fullname() != 'builtins.object':
387+
if setattr_meth and setattr_meth.info.fullname != 'builtins.object':
388388
setattr_func = function_type(setattr_meth, mx.builtin_type('builtins.function'))
389389
bound_type = bind_self(setattr_func, mx.self_type)
390390
typ = map_instance_to_supertype(itype, setattr_meth.info)
@@ -557,10 +557,10 @@ def analyze_var(name: str,
557557
result = signature
558558
else:
559559
if not var.is_ready:
560-
mx.not_ready_callback(var.name(), mx.context)
560+
mx.not_ready_callback(var.name, mx.context)
561561
# Implicit 'Any' type.
562562
result = AnyType(TypeOfAny.special_form)
563-
fullname = '{}.{}'.format(var.info.fullname(), name)
563+
fullname = '{}.{}'.format(var.info.fullname, name)
564564
hook = mx.chk.plugin.get_attribute_hook(fullname)
565565
if result and not mx.is_lvalue and not implicit:
566566
result = analyze_descriptor_access(mx.original_type, result, mx.builtin_type,
@@ -646,7 +646,7 @@ def analyze_class_attribute_access(itype: Instance,
646646
# can't be accessed on the class object.
647647
if node.implicit and isinstance(node.node, Var) and node.node.is_final:
648648
mx.msg.fail(message_registry.CANNOT_ACCESS_FINAL_INSTANCE_ATTR
649-
.format(node.node.name()), mx.context)
649+
.format(node.node.name), mx.context)
650650

651651
# An assignment to final attribute on class object is also always an error,
652652
# independently of types.
@@ -714,7 +714,7 @@ def analyze_class_attribute_access(itype: Instance,
714714

715715
if isinstance(node.node, TypeVarExpr):
716716
mx.msg.fail(message_registry.CANNOT_USE_TYPEVAR_AS_EXPRESSION.format(
717-
info.name(), name), mx.context)
717+
info.name, name), mx.context)
718718
return AnyType(TypeOfAny.from_error)
719719

720720
if isinstance(node.node, TypeInfo):
@@ -841,7 +841,7 @@ def type_object_type(info: TypeInfo, builtin_type: Callable[[str], Instance]) ->
841841
method = new_method.node
842842
is_new = True
843843
else:
844-
if init_method.node.info.fullname() == 'builtins.object':
844+
if init_method.node.info.fullname == 'builtins.object':
845845
# Both are defined by object. But if we've got a bogus
846846
# base class, we can't know for sure, so check for that.
847847
if info.fallback_to_any:

mypy/checkstrformat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ def check_simple_str_interpolation(self, specifiers: List[ConversionSpecifier],
655655
rep_types = rhs_type.items
656656
elif isinstance(rhs_type, AnyType):
657657
return
658-
elif isinstance(rhs_type, Instance) and rhs_type.type.fullname() == 'builtins.tuple':
658+
elif isinstance(rhs_type, Instance) and rhs_type.type.fullname == 'builtins.tuple':
659659
# Assume that an arbitrary-length tuple has the right number of items.
660660
rep_types = [rhs_type.args[0]] * len(checkers)
661661
elif isinstance(rhs_type, UnionType):
@@ -973,7 +973,7 @@ def custom_special_method(typ: Type, name: str,
973973
method = typ.type.get(name)
974974
if method and isinstance(method.node, (SYMBOL_FUNCBASE_TYPES, Decorator, Var)):
975975
if method.node.info:
976-
return not method.node.info.fullname().startswith('builtins.')
976+
return not method.node.info.fullname.startswith('builtins.')
977977
return False
978978
if isinstance(typ, UnionType):
979979
if check_all:

0 commit comments

Comments
 (0)