-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Add support for __slots__
in python 3.10
#1893
Comments
hey @patrick91 I was trying my luck with adding |
@nrbnlulu we could still allow to users to enable slots manually maybe :) field names have to be unique, so maybe we are fine? also maybe we could find a way to prevent slots from being applied to root level types (maybe types that extend other types?) |
Sure, that is not the problem though hehe... but if you mentioned this, I thought to do somthing like this: def _gte_310() -> bool:
return sys.version_info >= (3, 10)
# inside strawberry.type we expose the slots argument
def _wrap_dataclass(cls: Type, slots: bool = _gte_310()):
"""Wrap a strawberry.type class with a dataclass and check for any issues
before doing so"""
# Ensure all Fields have been properly type-annotated
_check_field_annotations(cls)
return dataclasses.dataclass(slots=slots)(cls) This would prevent to do
Unique where? at all the schema? does fields get renamed implicitly by strawberry? |
I think we can backport this feature to older versions of python :)
Unique per type :) we don't do any renaming when extending, I can't remember if we error out, if that's not the case we should :) |
lets continue the discussion on the PR |
In python 3.10 you can use
slots=True
when applying the dataclasses decoratorsee https://docs.python.org/3.10/whatsnew/3.10.html#slots
we should think about whether we expose this to end users, like so:
or if we enable it automatically (but we should still allow to disable it if that's the case)
Upvote & Fund
The text was updated successfully, but these errors were encountered: