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

[DRAFT] Tweak annotation population to better maintain field definition ordering #3561

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion strawberry/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ def _check_field_annotations(cls: Type[Any]) -> None:

https://github.com/python/cpython/blob/6fed3c85402c5ca704eb3f3189ca3f5c67a08d19/Lib/dataclasses.py#L881-L884
"""
cls_annotations = cls.__dict__.get("__annotations__", {})
original_annotations = cls.__dict__.get("__annotations__", {})
cls_annotations = {
a: t for a, t in original_annotations.items() if a not in cls.__dict__
}
cls.__annotations__ = cls_annotations

for field_name, field_ in cls.__dict__.items():
if field_name in original_annotations:
cls_annotations[field_name] = original_annotations[field_name]

if not isinstance(field_, (StrawberryField, dataclasses.Field)):
# Not a dataclasses.Field, nor a StrawberryField. Ignore
continue
Expand Down
Loading