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

Use C3 compatible ExtensionClass #982

Closed
wants to merge 12 commits into from
Closed

Conversation

icemac
Copy link
Member

@icemac icemac commented Jun 24, 2021

No description provided.

Michael Howitz and others added 5 commits June 14, 2021 14:13
…onClass.Base.

There are no more TypeError `Cannot create a consistent method resolution order (MRO)`.
But it breaks because of a missing attribute `_Persistent__flags` which should have
been set during `persistent.Persistent.__new__()`
@icemac
Copy link
Member Author

icemac commented Jun 24, 2021

The tests now run with activated EXTENSIONCLASS_C3_MRO. There seem to be currently two main problems:

  • ZCatalog does not have a consistent MRO.
  • Starting Zope in the tests has a problem with None.

@d-maurer
Copy link
Contributor

d-maurer commented Jun 24, 2021 via email

@icemac
Copy link
Member Author

icemac commented Jun 25, 2021

After fixing the linter complaints the tests got green for the c3 variant. So I added to classic one to see what the changes break there: Some reprs are broken: they no longer use the __repr__ method provided by OFS.SimpleItem.PathReprProvider. Do we need a different class hierarchy here or could this be fixable for both MROs?

This reverts commit 6d8a9b4.
Apparently, forcing the use of the latest `AccessControl` via explicit `versions` was not necessary
@d-maurer
Copy link
Contributor

d-maurer commented Jun 25, 2021

Do we need a different class hierarchy here or could this be fixable for both MROs?

We could try to move Item before ObjectManager in OFS.Folder.__bases__. We would then need to explicitly set Folder.__len__ = ObjectManager.__len__ to prevent the use of the wrong Item.__len__.
On second look, this is not enough. Regarding __len__, we could simply delete the definition in Item (it does what Python does anyway when there is no __len__ definition). But there are also objectIds, objectValues and objectItems which need to be taken from ObjectManager and not from Item.
The most promising (regarding compatiblity) approach is likely to refactor Item into BaseItem (with just the basic item methods) and Item (adding __len__, object*). In Folder, we could then have BaseItem, ObjectManager, Collection ... as __bases__.

…Item` is a base class with can precede `ObjectManager` in the `__bases__` of a class definition. Apply to `OFS.Folder.Folder`
@d-maurer
Copy link
Contributor

I have implemented the idea from the previous comment: tests now succeed (with the exception of a catalog test under Windows -- almost surely unrelated to the MRO).

The wrong __repr__, observed with Folder, applies likely to other classes deriving from ObjectManager, too. Likely, for most of them corresponding tests are missing and the problem will only be detected by chance. Fortunately, a wrong __repr__ is typically not fatal (but just hampers problem analysis).

@d-maurer
Copy link
Contributor

d-maurer commented Jul 1, 2021

The wrong __repr__, observed with Folder, applies likely to other classes deriving from ObjectManager, too. Likely, for most of them corresponding tests are missing and the problem will only be detected by chance. Fortunately, a wrong __repr__ is typically not fatal (but just hampers problem analysis).

Likely, this means that we should not go this route: someone who does not call for C3_MRO should (likely) not need to review and adapt his class hierarchies.
An alternative would be to use different inheritance orders depending on C3_MRO where the C3 and traditional orders give different results.

@icemac
Copy link
Member Author

icemac commented Apr 13, 2022

@d-maurer Do you see any future for this PR and C3 compatible classes in Zope or should we call it an experiment which showed that we cannot be C3 compatible because of our heritage?

@d-maurer
Copy link
Contributor

@d-maurer Do you see any future for this PR and C3 compatible classes in Zope or should we call it an experiment which showed that we cannot be C3 compatible because of our heritage?

I believe that C3 is possible. But it requires a lot of adaptation, not only in Zope itself but also in many packages depending on Zope. It might be difficult to maintain a switch between classic and C3 resolution controlled via an envvar (because the class inheritance structure may differ considerably).

C3 is a prerequisite to give super a well defined semantics. Apart from that, I find the classic method resolution far more intuitive and predictable than C3. It might not be worth to switch to C3: we lose a reliable super but keep an intuitive method resolution order.

@icemac
Copy link
Member Author

icemac commented Apr 14, 2022

@d-maurer Thank you for your statement. I am going to end the C3 experiment now as I see no way to get all needed parties on board. I do not see the manpower to maintain two resolution orders forever and having just partial C3 support does not help either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants