-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
TypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass.
from typing import TypeAliasType
import weakref
import gc
class S(str):
pass
def still_alive(ref):
obj = ref()
if not isinstance(obj, S):
return False
T = obj.T
if not isinstance(T, TypeAliasType):
return False
return T
name = S("name")
T = TypeAliasType(name, int)
name.T = T
ref = weakref.ref(name)
assert still_alive(ref)
del name
del T
gc.collect()
gc.collect()
assert still_alive(ref)
del ref().T
assert not still_alive(ref)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-140000: Traverse
name
attribute forTypeVar
,TypeVarTuple
,TypeAliasType
,ParamSpec
#140016 - [3.14] gh-140000: Traverse
name
attribute forTypeVar
,TypeVarTuple
,TypeAliasType
,ParamSpec
(GH-140016) #140063 - [3.13] gh-140000: Traverse
name
attribute forTypeVar
,TypeVarTuple
,TypeAliasType
,ParamSpec
(GH-140016) #140073
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error