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
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:
TypeError: __class__ assignment: 'B' object layout differs from 'A'
float
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:
__slots__ = ()
A
B
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?
int
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.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
bicofevo commentedDec 5, 2022
Bug report
Next code:
Results in
TypeError: __class__ assignment: 'B' object layout differs from 'A'
The very same code for
float
won’t throw any error:Adding
__slots__ = ()
toA
andB
definitions fixes the error:Is it an expected difference in behavior for
int
andfloat
?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
The text was updated successfully, but these errors were encountered: