Int and float different behavior with TypeError "object layout differs from"

Minimal repro to illustrate my question:

results in TypeError: __class__ assignment: 'B' object layout differs from 'A'

The very same code for float won’t throw any error:

I also found out that if I add __slots__ = () attribute to both A and B definitions no errors will appear in the __class__ reassignment.

Is this different behavior for int and float an expected one?

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.

Python version 3.10.8.

Navigation Menu

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.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

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

TypeError: __class__ assignment: 'A' object layout differs from 'B' #2361

@gitlab-importer

gitlab-importer commented Aug 2, 2016

Sorry, something went wrong.

@gitlab-importer

No branches or pull requests

@gitlab-importer

  • Python Home
  • Documentation
  • Developer's Guide
  • Random Issue
  • Issues with patch
  • Easy issues
  • Login Remember me?
  • Lost your login?
  • Committer List
  • Tracker Documentation
  • Tracker Development
  • Report Tracker Problem

__class__ assignment object layout differs from

This issue tracker has been migrated to GitHub , and is currently read-only . For more information, see the GitHub FAQs in the Python's Developer Guide.

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/48850

Created on 2008-12-08 21:25 by terry.reedy , last changed 2022-04-11 14:56 by admin . This issue is now closed .