-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from hculea/hculea/add-python-support-in-type…
…share Add Typeshare support for Python
- Loading branch information
Showing
55 changed files
with
2,133 additions
and
286 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel, ConfigDict, Field | ||
from typing import List, Literal, Union | ||
|
||
|
||
class AnonymousStructWithRenameListInner(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `List` of the `AnonymousStructWithRename` Rust enum | ||
""" | ||
list: List[str] | ||
|
||
class AnonymousStructWithRenameLongFieldNamesInner(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `LongFieldNames` of the `AnonymousStructWithRename` Rust enum | ||
""" | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
some_long_field_name: str | ||
and_: bool = Field(alias="and") | ||
but_one_more: List[str] | ||
|
||
class AnonymousStructWithRenameKebabCaseInner(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `KebabCase` of the `AnonymousStructWithRename` Rust enum | ||
""" | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
another_list: List[str] = Field(alias="another-list") | ||
camel_case_string_field: str = Field(alias="camelCaseStringField") | ||
something_else: bool = Field(alias="something-else") | ||
|
||
class AnonymousStructWithRenameTypes(str, Enum): | ||
LIST = "list" | ||
LONG_FIELD_NAMES = "longFieldNames" | ||
KEBAB_CASE = "kebabCase" | ||
|
||
class AnonymousStructWithRenameList(BaseModel): | ||
type: Literal[AnonymousStructWithRenameTypes.LIST] = AnonymousStructWithRenameTypes.LIST | ||
content: AnonymousStructWithRenameListInner | ||
|
||
class AnonymousStructWithRenameLongFieldNames(BaseModel): | ||
type: Literal[AnonymousStructWithRenameTypes.LONG_FIELD_NAMES] = AnonymousStructWithRenameTypes.LONG_FIELD_NAMES | ||
content: AnonymousStructWithRenameLongFieldNamesInner | ||
|
||
class AnonymousStructWithRenameKebabCase(BaseModel): | ||
type: Literal[AnonymousStructWithRenameTypes.KEBAB_CASE] = AnonymousStructWithRenameTypes.KEBAB_CASE | ||
content: AnonymousStructWithRenameKebabCaseInner | ||
|
||
AnonymousStructWithRename = Union[AnonymousStructWithRenameList, AnonymousStructWithRenameLongFieldNames, AnonymousStructWithRenameKebabCase] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel | ||
from typing import Dict, List, Literal, Union | ||
|
||
|
||
class ItemDetailsFieldValue(BaseModel): | ||
hello: str | ||
|
||
class AdvancedColorsTypes(str, Enum): | ||
STRING = "String" | ||
NUMBER = "Number" | ||
NUMBER_ARRAY = "NumberArray" | ||
REALLY_COOL_TYPE = "ReallyCoolType" | ||
ARRAY_REALLY_COOL_TYPE = "ArrayReallyCoolType" | ||
DICTIONARY_REALLY_COOL_TYPE = "DictionaryReallyCoolType" | ||
|
||
class AdvancedColorsString(BaseModel): | ||
t: Literal[AdvancedColorsTypes.STRING] = AdvancedColorsTypes.STRING | ||
c: str | ||
|
||
class AdvancedColorsNumber(BaseModel): | ||
t: Literal[AdvancedColorsTypes.NUMBER] = AdvancedColorsTypes.NUMBER | ||
c: int | ||
|
||
class AdvancedColorsNumberArray(BaseModel): | ||
t: Literal[AdvancedColorsTypes.NUMBER_ARRAY] = AdvancedColorsTypes.NUMBER_ARRAY | ||
c: List[int] | ||
|
||
class AdvancedColorsReallyCoolType(BaseModel): | ||
t: Literal[AdvancedColorsTypes.REALLY_COOL_TYPE] = AdvancedColorsTypes.REALLY_COOL_TYPE | ||
c: ItemDetailsFieldValue | ||
|
||
class AdvancedColorsArrayReallyCoolType(BaseModel): | ||
t: Literal[AdvancedColorsTypes.ARRAY_REALLY_COOL_TYPE] = AdvancedColorsTypes.ARRAY_REALLY_COOL_TYPE | ||
c: List[ItemDetailsFieldValue] | ||
|
||
class AdvancedColorsDictionaryReallyCoolType(BaseModel): | ||
t: Literal[AdvancedColorsTypes.DICTIONARY_REALLY_COOL_TYPE] = AdvancedColorsTypes.DICTIONARY_REALLY_COOL_TYPE | ||
c: Dict[str, ItemDetailsFieldValue] | ||
|
||
AdvancedColors = Union[AdvancedColorsString, AdvancedColorsNumber, AdvancedColorsNumberArray, AdvancedColorsReallyCoolType, AdvancedColorsArrayReallyCoolType, AdvancedColorsDictionaryReallyCoolType] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel | ||
from typing import List, Literal, Union | ||
|
||
|
||
class ItemDetailsFieldValue(BaseModel): | ||
""" | ||
Struct comment | ||
""" | ||
pass | ||
class AdvancedColorsTypes(str, Enum): | ||
STRING = "String" | ||
NUMBER = "Number" | ||
UNSIGNED_NUMBER = "UnsignedNumber" | ||
NUMBER_ARRAY = "NumberArray" | ||
REALLY_COOL_TYPE = "ReallyCoolType" | ||
|
||
class AdvancedColorsString(BaseModel): | ||
""" | ||
This is a case comment | ||
""" | ||
type: Literal[AdvancedColorsTypes.STRING] = AdvancedColorsTypes.STRING | ||
content: str | ||
|
||
class AdvancedColorsNumber(BaseModel): | ||
type: Literal[AdvancedColorsTypes.NUMBER] = AdvancedColorsTypes.NUMBER | ||
content: int | ||
|
||
class AdvancedColorsUnsignedNumber(BaseModel): | ||
type: Literal[AdvancedColorsTypes.UNSIGNED_NUMBER] = AdvancedColorsTypes.UNSIGNED_NUMBER | ||
content: int | ||
|
||
class AdvancedColorsNumberArray(BaseModel): | ||
type: Literal[AdvancedColorsTypes.NUMBER_ARRAY] = AdvancedColorsTypes.NUMBER_ARRAY | ||
content: List[int] | ||
|
||
class AdvancedColorsReallyCoolType(BaseModel): | ||
""" | ||
Comment on the last element | ||
""" | ||
type: Literal[AdvancedColorsTypes.REALLY_COOL_TYPE] = AdvancedColorsTypes.REALLY_COOL_TYPE | ||
content: ItemDetailsFieldValue | ||
|
||
# Enum comment | ||
AdvancedColors = Union[AdvancedColorsString, AdvancedColorsNumber, AdvancedColorsUnsignedNumber, AdvancedColorsNumberArray, AdvancedColorsReallyCoolType] | ||
class AdvancedColors2Types(str, Enum): | ||
STRING = "string" | ||
NUMBER = "number" | ||
NUMBER_ARRAY = "number-array" | ||
REALLY_COOL_TYPE = "really-cool-type" | ||
|
||
class AdvancedColors2String(BaseModel): | ||
""" | ||
This is a case comment | ||
""" | ||
type: Literal[AdvancedColors2Types.STRING] = AdvancedColors2Types.STRING | ||
content: str | ||
|
||
class AdvancedColors2Number(BaseModel): | ||
type: Literal[AdvancedColors2Types.NUMBER] = AdvancedColors2Types.NUMBER | ||
content: int | ||
|
||
class AdvancedColors2NumberArray(BaseModel): | ||
type: Literal[AdvancedColors2Types.NUMBER_ARRAY] = AdvancedColors2Types.NUMBER_ARRAY | ||
content: List[int] | ||
|
||
class AdvancedColors2ReallyCoolType(BaseModel): | ||
""" | ||
Comment on the last element | ||
""" | ||
type: Literal[AdvancedColors2Types.REALLY_COOL_TYPE] = AdvancedColors2Types.REALLY_COOL_TYPE | ||
content: ItemDetailsFieldValue | ||
|
||
AdvancedColors2 = Union[AdvancedColors2String, AdvancedColors2Number, AdvancedColors2NumberArray, AdvancedColors2ReallyCoolType] |
19 changes: 19 additions & 0 deletions
19
core/data/tests/can_generate_algebraic_enum_with_skipped_variants/output.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel | ||
from typing import Literal, Union | ||
|
||
|
||
class SomeEnumTypes(str, Enum): | ||
A = "A" | ||
C = "C" | ||
|
||
class SomeEnumA(BaseModel): | ||
type: Literal[SomeEnumTypes.A] = SomeEnumTypes.A | ||
|
||
class SomeEnumC(BaseModel): | ||
type: Literal[SomeEnumTypes.C] = SomeEnumTypes.C | ||
content: int | ||
|
||
SomeEnum = Union[SomeEnumA, SomeEnumC] |
45 changes: 45 additions & 0 deletions
45
core/data/tests/can_generate_anonymous_struct_with_skipped_fields/output.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel | ||
from typing import Literal, Union | ||
|
||
|
||
class AutofilledByUsInner(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `Us` of the `AutofilledBy` Rust enum | ||
""" | ||
uuid: str | ||
""" | ||
The UUID for the fill | ||
""" | ||
|
||
class AutofilledBySomethingElseInner(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `SomethingElse` of the `AutofilledBy` Rust enum | ||
""" | ||
uuid: str | ||
""" | ||
The UUID for the fill | ||
""" | ||
|
||
class AutofilledByTypes(str, Enum): | ||
US = "Us" | ||
SOMETHING_ELSE = "SomethingElse" | ||
|
||
class AutofilledByUs(BaseModel): | ||
""" | ||
This field was autofilled by us | ||
""" | ||
type: Literal[AutofilledByTypes.US] = AutofilledByTypes.US | ||
content: AutofilledByUsInner | ||
|
||
class AutofilledBySomethingElse(BaseModel): | ||
""" | ||
Something else autofilled this field | ||
""" | ||
type: Literal[AutofilledByTypes.SOMETHING_ELSE] = AutofilledByTypes.SOMETHING_ELSE | ||
content: AutofilledBySomethingElseInner | ||
|
||
# Enum keeping track of who autofilled a field | ||
AutofilledBy = Union[AutofilledByUs, AutofilledBySomethingElse] |
Oops, something went wrong.