Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
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.
fromtypingimportTypeAliasTypeimportweakrefimportgcclassS(str):passdefstill_alive(ref):obj=ref()ifnotisinstance(obj,S):returnFalseT=obj.Tifnotisinstance(T,TypeAliasType):returnFalsereturnTname=S("name")T=TypeAliasType(name,int)name.T=Tref=weakref.ref(name)assertstill_alive(ref)delnamedelTgc.collect()gc.collect()assertstill_alive(ref)delref().Tassertnotstill_alive(ref)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-140000: Traverse
nameattribute forTypeVar,TypeVarTuple,TypeAliasType,ParamSpec#140016 - [3.14] gh-140000: Traverse
nameattribute forTypeVar,TypeVarTuple,TypeAliasType,ParamSpec(GH-140016) #140063 - [3.13] gh-140000: Traverse
nameattribute forTypeVar,TypeVarTuple,TypeAliasType,ParamSpec(GH-140016) #140073