Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeAliasType can leak memory if name is a str subclass #140000

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error
@JelleZijlstra

Description

@JelleZijlstra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp