Open patrick91 opened 2 years ago
hey @patrick91 I was trying my luck with adding __slots__
to strawberry.type
and I have a question.
Does strawberry requires all of the queries / mutations / subscription to be under one huge child that is inheriting from all other?
or they are composed and does not require inheritance.
If the first is the case I'm afraid it would be impossible unless you have all unique field names and do some hacks, see this SO for more detail
@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?)
we could still allow to users to enable slots manually maybe :)
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 pytest.mark.parameterize
all over the place.
What are your thoughts?
field names have to be unique, so maybe we are fine?
Unique where? at all the schema? does fields get renamed implicitly by strawberry?
we could still allow to users to enable slots manually maybe :)
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
pytest.mark.parameterize
all over the place. What are your thoughts?
I think we can backport this feature to older versions of python :)
field names have to be unique, so maybe we are fine?
Unique where? at all the schema? does fields get renamed implicitly by strawberry?
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