Skip to content

Commit 8c742b8

Browse files
committed
Rename visitor + performance
1 parent b15f0dd commit 8c742b8

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 (
@@ -246,7 +246,7 @@ def visit_instance(self, t: Instance) -> Type:
246246
def visit_type_var(self, t: TypeVarType) -> Type:
247247
repl = self.variables.get(t.id, t)
248248

249-
if has_type_vars_default(repl):
249+
if has_type_var_like_default(repl):
250250
if repl in self.recursive_guard:
251251
return repl
252252
self.recursive_guard.add(repl)

mypy/types.py

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

34273427

3428-
class HasTypeVarDefault(BoolTypeQuery):
3428+
class HasTypeVarLikeDefault(BoolTypeQuery):
34293429
def __init__(self) -> None:
34303430
super().__init__(ANY_STRATEGY)
34313431
self.skip_alias_target = True
@@ -3440,8 +3440,13 @@ def visit_param_spec(self, t: ParamSpecType) -> bool:
34403440
return t.has_default()
34413441

34423442

3443-
def has_type_vars_default(typ: Type) -> bool:
3444-
return typ.accept(HasTypeVarDefault())
3443+
# Use singleton since this is hot (note: call reset() before using)
3444+
_has_type_var_like_default: Final = HasTypeVarLikeDefault()
3445+
3446+
3447+
def has_type_var_like_default(typ: Type) -> bool:
3448+
_has_type_var_like_default.reset()
3449+
return typ.accept(_has_type_var_like_default)
34453450

34463451

34473452
class HasParamSpecs(BoolTypeQuery):

0 commit comments

Comments
 (0)