Skip to content

Commit e6a2a0e

Browse files
committed
Rename visitor + performance
1 parent baee3ef commit e6a2a0e

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 (
@@ -266,7 +266,7 @@ def visit_type_var(self, t: TypeVarType) -> Type:
266266
t = t.copy_modified(upper_bound=t.upper_bound.accept(self))
267267
repl = self.variables.get(t.id, t)
268268

269-
if has_type_vars_default(repl):
269+
if has_type_var_like_default(repl):
270270
if repl in self.recursive_guard:
271271
return repl
272272
self.recursive_guard.add(repl)

mypy/types.py

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

34233423

3424-
class HasTypeVarDefault(BoolTypeQuery):
3424+
class HasTypeVarLikeDefault(BoolTypeQuery):
34253425
def __init__(self) -> None:
34263426
super().__init__(ANY_STRATEGY)
34273427
self.skip_alias_target = True
@@ -3436,8 +3436,13 @@ def visit_param_spec(self, t: ParamSpecType) -> bool:
34363436
return t.has_default()
34373437

34383438

3439-
def has_type_vars_default(typ: Type) -> bool:
3440-
return typ.accept(HasTypeVarDefault())
3439+
# Use singleton since this is hot (note: call reset() before using)
3440+
_has_type_var_like_default: Final = HasTypeVarLikeDefault()
3441+
3442+
3443+
def has_type_var_like_default(typ: Type) -> bool:
3444+
_has_type_var_like_default.reset()
3445+
return typ.accept(_has_type_var_like_default)
34413446

34423447

34433448
class HasParamSpecs(BoolTypeQuery):

0 commit comments

Comments
 (0)