Skip to content

Add a few more tests for mypyc_attr native_class (dunder methods and metaclasses) #18999

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

svalentin
Copy link
Collaborator

No description provided.

Testing dunder methods and metaclasses
@svalentin svalentin requested a review from JukkaL April 29, 2025 15:47
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions. Can you also check the build failures?

pass

@mypyc_attr(native_class=True)
class A(metaclass=M): # E: Class is marked as native_class=True but it can't be a native class
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention in the error message that the metaclass is not supported with a native class?

f = native.Foo()
assert(hasattr(f, 'bar'))
assert(f.bar == 'start')
f.bar = 'test'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test that the __set__ method is called, and this doesn't just replace the descriptor? A hacky way would be to set some global flag the __set__ is called.

assert(hasattr(f, 'bar'))
assert(f.bar == 'start')
f.bar = 'test'
assert(f.bar == 'test')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here it would be good to ensure that __get__ (and __delete__ below) actually get called.

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

Successfully merging this pull request may close these issues.

2 participants