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

Inconsistency in handling None handlers in the Python and C implementations of pickle #93627

Open
Labels
3.10only security fixes3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error
@serhiy-storchaka

Description

@serhiy-storchaka

In the Python implementation ofpickle setting some handlers to None causes a fallback to other methods.

  • SettingPickler.reducer_override to None has the same effect as not setting this attribute -- falling back to other methods.
  • Setting thedispatch_table to None leads to falling back to__reduce_ex__.
  • Setting the__reduce_ex__ attribute to None leads to falling back to__reduce__.
  • Setting the__setstate__ attribute to None leads to falling back to the default implementation of__setstate__ (setting__dict__ and slots).

In the C implementation all this leads toTypeError: 'NoneType' object is not callable.

Thecopy module follows the Python implementation ofpickle, except that it fails for any false value of__reduce__, not just None.

In most other code setting a dunder method to None leads to a TypeError (either raise explicitly or just generic "'NoneType' object is not callable").

We should decide what behavior should be in thepickle andcopy module. On one hand, the Python implementation was primary. On other hand, it was inconsistent between thepickle andcopy modules and was already changed in the past, the C implementation ofpickle is now used by most users, and it is more consistent with other code.

See also:
https://mail.python.org/archives/list/python-dev@python.org/thread/YGAK34DRWJFSIV2VZ4NC2J24XO37GCMM/
https://docs.python.org/3.10/reference/datamodel.html#id2
#70146
#55781
#60755

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp