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

3.12.0b4 Backwards incompatible change with reassignment ofcls.__new__ andsuper() #106917

Closed
Assignees
carljm
Labels
3.12only security fixes3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@cdce8p

Description

@cdce8p

Bug report

Noticed this while testing3.12.0b4. While in my particular case I can work around it, it never the less is a change in behavior to3.11.

classFixedIntType(int):_signed:booldef__new__(cls,*args,**kwargs):print(f"{cls},{args=}")returnsuper().__new__(cls,*args,**kwargs)def__init_subclass__(cls,signed:int|None=None)->None:super().__init_subclass__()ifsignedisnotNone:cls._signed=signedif"__new__"notincls.__dict__:cls.__new__=cls.__new__# <-- This line triggers the errorclassuint_t(FixedIntType,signed=False):passclassCustomInt(uint_t):def__new__(cls,value:int=0):returnsuper().__new__(cls,value)defwith_id(self,value:int):returntype(self)(value)CustomInt().with_id(1024)
<class '__main__.CustomInt'>, args=(0,)<class '__main__.CustomInt'>, args=(<class '__main__.CustomInt'>, 1024)Traceback (most recent call last):  File "/.../cpython/test.py", line 26, in <module>    CustomInt().with_id(1024)  File "/.../cpython/test.py", line 24, in with_id    return type(self)(value)           ^^^^^^^^^^^^^^^^^  File "/.../cpython/test.py", line 21, in __new__    return super().__new__(cls, value)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/.../cpython/test.py", line 6, in __new__    return super().__new__(cls, *args, **kwargs)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ValueError: int() base must be >= 2 and <= 36, or 0

Withoutcls.__new__ = cls.__new__

<class '__main__.CustomInt'>, args=(0,)<class '__main__.CustomInt'>, args=(1024,)

I bisected the issue to#103497.
/CC:@carljm

Your environment

  • CPython versions tested on:3.120b4
  • Operating system and architecture: macOS ARM64

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs 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