Skip to content

Changes to support running the client under future annotations #1

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

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

brunomlopes
Copy link
Contributor

@brunomlopes brunomlopes commented Jul 25, 2023

Hi,

I've been trying to work with the python dtos for a large project, and found some issues with the client.

These changes below seem to be needed for some of the cases.
The generated code also needed to be corrected, to pull some classes to the top of the file, before they are referenced.

These changes were done to support self-referencial type annotations in python 3.11 (via from future import annotations ).
Not sure if they are correct.

The main scenarios are things like:

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass
class PagedResults:
    current_page: int = 0
    total_results: int = 0
    page_size: int = 0

T = TypeVar('T')

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass
class PagedResults1(Generic[T], PagedResults):
    results: Optional[List[T]] = None

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass
class AResponseWithPagedResults:
    paged_results: Optional[PagedResults1[SomeDto]] = None

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass
class HierarchicalDto:
    children: Optional[List[HierarchicalDto]] = None

In order to support self-referencial type annotations in python 3.11 (via from __future__ import annotations )
There are a few changes needed for code to run.

The main scenarios are things like:

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@DataClass
class PagedResults:
    current_page: int = 0
    total_results: int = 0
    page_size: int = 0

T = TypeVar('T')

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@DataClass
class PagedResults1(Generic[T], PagedResults):
    results: Optional[List[T]] = None

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@DataClass
class AResponseWithPagedResults:
    paged_results: Optional[PagedResults1[SomeDto]] = None

@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)
@DataClass
class HierarchicalDto:
    children: Optional[List[HierarchicalDto]] = None
@mythz mythz merged commit cc21dc5 into ServiceStack:main Jul 25, 2023
@mythz
Copy link
Member

mythz commented Jul 25, 2023

great, thx for the PR!

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