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

dict.update() mutation check too broad #132617

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@colesbury

Description

@colesbury

Bug report

Thedict.update() modification check can be erroneously triggered by modifications todifferent dictionaries that happen toshare the underlying keys objects.

For example, in the following program, the creation and modification of thef2 object can lead to an incorrectRuntimeError raised in the main thread that operates on distinct dictionaries.

importtimeimportthreadingb=threading.Barrier(2)classFoo:passclassMyStr(str):def__hash__(self):returnsuper().__hash__()def__eq__(self,other):time.sleep(0.1)returnsuper().__eq__(other)defthread():b.wait()time.sleep(0.05)f2=Foo()f2.a="a"f2.b="b"f2.c="c"defmain():t1=threading.Thread(target=thread)t1.start()b.wait()f1=Foo()f1.a="a"f1.b="b"x= {}x[MyStr("a")]=MyStr("a")x.update(f1.__dict__)t1.join()if__name__=="__main__":main()
Traceback (most recent call last):  File "/home/sgross/cpython/bad.py", line 44, in <module>    main()    ~~~~^^  File "/home/sgross/cpython/bad.py", line 39, in main    x.update(f1.__dict__)    ~~~~~~~~^^^^^^^^^^^^^RuntimeError: dict mutated during update

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-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