Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Int and float different behavior with TypeError “object layout differs from” #100037

Open
bicofevo opened this issue Dec 5, 2022 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@bicofevo
Copy link

bicofevo commented Dec 5, 2022

Bug report

Next code:

class A(int):
    pass

class B(int):
    pass

a = A(1)
a.__class__ = B

Results in TypeError: __class__ assignment: 'B' object layout differs from 'A'
The very same code for float won’t throw any error:

class C(float):
    pass

class D(float):
    pass

c = C(1.2)
c.__class__ = D

Adding __slots__ = () to A and B definitions fixes the error:

class A(int):
    __slots__ = ()

class B(int):
    __slots__ = ()

a = A(1)
a.__class__ = B

Is it an expected difference in behavior for int and float?

P.S. Real code is in the autoreload extension for jupyter, where it tries to reload the changed class and if it’s a child of int it throws this error.

Your environment

  • CPython versions tested on: 3.10.8
  • Operating system and architecture: Windows 10, 64bit
@bicofevo bicofevo added the type-bug An unexpected behavior, bug, or error label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant