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

Look into __mro_entries__ #449

Closed
ronaldoussoren opened this issue Mar 5, 2022 · 2 comments
Closed

Look into __mro_entries__ #449

ronaldoussoren opened this issue Mar 5, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@ronaldoussoren
Copy link
Owner

ronaldoussoren commented Mar 5, 2022

Appearently it is (once again?) possible to inherit from a non-class. That could make it more convenient to implement a protocol:

Currently:

class MyObject (NSObject, protocols=[objc.protocolNamed("SomeProtocol")]):
    ...

Possible change:

class MyObject (NSObject, objc.protocolNamed("SomeProtocol")):
    ...

This may require implementing a __mro_entries__ method in objc.formal_protocol.

Disadvantage is that makes the interface for complex by having two different ways to denote that a class implements a protocol. That said, this may by helpful with static typing (especially when the representation of protocols in type stubs is some kind of type). See also #419

@ronaldoussoren ronaldoussoren added the enhancement New feature or request label Mar 5, 2022
@ronaldoussoren
Copy link
Owner Author

The code for handling protocols in the parent classes is present in class_new() in objc-class.m, however I get an exception when trying to use this functionality:

class MyObject(NSObject, objc.protocolNamed("NSObject"):
    ...

The exception:

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Implementing __mro_entries__ to ignore formal (and informal) protocols somewhat helps with this, in that the exception goes away, but also requires more work because the protocols are no longer present in the bases passed to class_new (haven't check yet if they do end up in the class dict)

@ronaldoussoren
Copy link
Owner Author

The PEP introducing __mro_entries__ mentions that this method is not meant to be used outside of the typing module:

NOTE: These two method names are reserved for use by the typing module and the generic types machinery, and any other use is discouraged. The reference implementation (with tests) can be found in [4], and the proposal was originally posted and discussed on the typing tracker, see [5].

I'm therefore closing this issue.

@ronaldoussoren ronaldoussoren closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant