Skip to content

Commit 84bede2

Browse files
committed
Rename visitor + performance
1 parent 2ffc838 commit 84bede2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

mypy/expandtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
flatten_nested_unions,
4545
get_proper_type,
4646
has_param_specs,
47-
has_type_vars_default,
47+
has_type_var_like_default,
4848
remove_trivial,
4949
)
5050
from mypy.typevartuples import (
@@ -250,7 +250,7 @@ def visit_type_var(self, t: TypeVarType) -> Type:
250250
t = t.copy_modified(upper_bound=t.upper_bound.accept(self))
251251
repl = self.variables.get(t.id, t)
252252

253-
if has_type_vars_default(repl):
253+
if has_type_var_like_default(repl):
254254
if repl in self.recursive_guard:
255255
return repl
256256
self.recursive_guard.add(repl)

mypy/types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ def has_type_vars(typ: Type) -> bool:
34413441
return typ.accept(HasTypeVars())
34423442

34433443

3444-
class HasTypeVarDefault(BoolTypeQuery):
3444+
class HasTypeVarLikeDefault(BoolTypeQuery):
34453445
def __init__(self) -> None:
34463446
super().__init__(ANY_STRATEGY)
34473447
self.skip_alias_target = True
@@ -3456,8 +3456,13 @@ def visit_param_spec(self, t: ParamSpecType) -> bool:
34563456
return t.has_default()
34573457

34583458

3459-
def has_type_vars_default(typ: Type) -> bool:
3460-
return typ.accept(HasTypeVarDefault())
3459+
# Use singleton since this is hot (note: call reset() before using)
3460+
_has_type_var_like_default: Final = HasTypeVarLikeDefault()
3461+
3462+
3463+
def has_type_var_like_default(typ: Type) -> bool:
3464+
_has_type_var_like_default.reset()
3465+
return typ.accept(_has_type_var_like_default)
34613466

34623467

34633468
class HasParamSpecs(BoolTypeQuery):

0 commit comments

Comments
 (0)