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

Side effect of FrozenJSON.__getattr__ not raising KeyError #46

Open
@hayemj

Description

@hayemj

Hi Luciano,

In chapter 22 you mention thatFrozenJSON.__getattr__() raising aKeyError is "not to confusing". However, today I discovered a side effect from this thatis confusing:copy.copy(FrozenJSON({'name': 'Jim Bo', 'class': 1982})) raises aRecursionError.

Indeed the documentation states that anAttributeError should be raised (https://docs.python.org/3/reference/datamodel.html#object.__getattr__) and apparently this is relied upon in the stdlib. In the copy implementation a new instance ofFrozenJSON is generated without the initializer being called. Then, when looking for some optional dunder methods (that are not found) the copy implementation triggers a__getattr__ call withself.__data not yet existing, triggering the recursion.

What I appreciate in your book is that you are always very precise about all types of unexpected side effects, so maybe you could consider spending some text on this in a future update.

Best regards, Michiel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp