-
-
Notifications
You must be signed in to change notification settings - Fork 3k
mypyc: Add support for new-style attrs API #15274
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
base: master
Are you sure you want to change the base?
Conversation
I can probably take a look tomorrow FWIW. I'm not sure how familiar Jelle is with mypyc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like a second pair of eyes, but here's my initial feedback. Thanks for the PR!
return d.fullname.split(".")[0] | ||
name = d.fullname.split(".")[0] | ||
if name == "attrs": | ||
raise ValueError("Slotted attrs classes are not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would use the builder error plumbing, but TBF mypyc's error reporting story is pretty terrible anyway (see "usability" under mypyc/mypyc#785).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really acceptable to raise ValueError
. This should report an error using the mypyc.errors.Errors
class.
"dataclasses.dataclass", | ||
"attr.s", | ||
"attr.attrs", | ||
"attrs.define", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, the MemberExpr for these have fullname
set to attr.define
which isn't included here... do you know why that's the case? If you remove the slots=False
argument, no error is raised. Are you sure mypyc is recognizing attrs' modern APIs?
import attrs
@attrs.define(slots=False)
class Person:
name: str
@attrs.define(slots=False)
class MyException(Exception):
level: int
def __str__(self) -> str:
return f"level {self.level} storm up ahead!"
(Also subclassing from Exception seems to be broken, but it's broken on main too.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't reproduce it. What version of attrs do you have installed in your environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(BTW, not sure how to assert a 'compilation error' in those tests.)
Co-authored-by: Richard Si <[email protected]>
@ichard26 can take another look? |
Fixes #15267.
We don't support slotted classes yet, so we'll be explicit about it.