-
Notifications
You must be signed in to change notification settings - Fork 99
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 Typeshare support for Python #169
Open
hculea
wants to merge
60
commits into
1Password:main
Choose a base branch
from
hculea:hculea/add-python-support-in-typeshare
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 49 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
90f7537
Add experimental typeshare support for Python
hculea ee5673c
Resolve clippy errors
hculea 78bca98
Resolve merge conflicts with latest main
hculea dfd6522
Resolve merge conflicts with latest main
hculea 0c14914
Add python as an option for the --lang flag
hculea 439783b
Add support for todo and priorly unsupported types
hculea d7f12d0
Leverage mutable self to remove RefCell around Module
hculea 2039818
Fix ParsedRusthThing typo
hculea 48a8adb
Merge branch 'main' into hculea/add-python-support-in-typeshare
MOmarMiraj 1427223
Merge branch '1Password:main' into hculea/add-python-support-in-types…
AndyTitu c9f4be4
Use serialization alias in renaming fields in Python
hculea ad6645a
Merge branch '1Password:main' into hculea/add-python-support-in-types…
hculea 459f596
Fix python serializing and deserialzing using pydantic Field aliasing…
AndyTitu fde8907
Fix indentation of writing config dict
AndyTitu ead7d3a
added None default to Optional python type
amandayu1 a74e4ce
Updated None default condition
amandayu1 9b5c4be
fixing optional field set to default
amandayu1 628608d
add fix for missing fields
amandayu1 8519dea
added fix
amandayu1 6786aad
changed fix
amandayu1 2d0e627
testing new approach
amandayu1 169b380
Merge pull request #1 from hculea/optional-fields-default-to-none
amandayu1 e6bea87
added clarifying comment for None default
amandayu1 d51d903
set optional field to None by default
amandayu1 aa2213d
Bring Python fork up to date with main
hculea eeaa0d1
Run cargo fmt
hculea e79b7b6
fix duplicated " = None = None"
CheatCod d98a3e2
fix duplicate
CheatCod 677cf13
add tests
CheatCod df4a611
add comments to test
CheatCod 77b7239
minor formatting
CheatCod b3536c8
Remove level of indentation of type alias on comments
MOmarMiraj 45e9e5f
Refactor Python Codegen to correctly top sort file and use typeshare …
MOmarMiraj c8026b0
Add Feature Flag for Python TS (#3)
MOmarMiraj e419246
Draft: Change tagged enum generation in python (#2)
CheatCod 53b25db
Merge remote-tracking branch 'upstream/main' into hculea/add-python-s…
MOmarMiraj fb666ca
Add python support and update cargo lock
MOmarMiraj 40206a7
fmt fix and fix rust doc
MOmarMiraj 7184b52
update test cases
MOmarMiraj 3d447df
Add mention of Python support in README
hculea a251db1
remove trailing comma
MOmarMiraj 03d600b
Merge branch 'hculea/add-python-support-in-typeshare' of github.com:h…
MOmarMiraj 61b6afd
Update unit enum to use enum values
MOmarMiraj 9810e7b
fmt fix
MOmarMiraj 92f6922
Remove config dict and allow unit enums to be serializble
MOmarMiraj 0f89783
fix tuple variant generation
CheatCod 90793c7
dedup union
CheatCod 40803c4
better error handling
CheatCod 23ecf7f
Merge pull request #4 from hculea/peter/fix-tuple-variant-generation
CheatCod ce97007
remove once-cell; use index-set
CheatCod 260fa75
update tests
CheatCod d4fabb6
add comments on unused function for generics
CheatCod 83001f7
refactor how union works. Note this requires the struct to be externa…
CheatCod 6afd25a
proper rename
CheatCod 0c9b8ac
use literal for tag keys
CheatCod a10d3e7
generate comments properly
CheatCod 3df3ece
fix type aliasing issue
CheatCod 533c75f
remove unneeded newlines
CheatCod 4a0bb0e
fix to confrom python's wonderful doc conventions
CheatCod a49914a
use enum for type
CheatCod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,72 @@ | ||
""" | ||
Generated by typeshare 1.12.0 | ||
""" | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel, ConfigDict, Field | ||
from typing import List, Union | ||
|
||
|
||
class AnonymousStructWithRenameList(BaseModel): | ||
""" | ||
Generated type representing the anonymous struct variant `List` of the `AnonymousStructWithRename` Rust enum | ||
""" | ||
list: List[str] | ||
|
||
|
||
class AnonymousStructWithRenameLongFieldNames(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 | ||
Lucretiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
but_one_more: List[str] | ||
|
||
|
||
class AnonymousStructWithRenameKebabCase(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 | ||
Lucretiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
something_else: bool = Field(alias="something-else") | ||
|
||
|
||
class AnonymousStructWithRenameTypes(str, Enum): | ||
LIST = "list" | ||
LONG_FIELD_NAMES = "longFieldNames" | ||
KEBAB_CASE = "kebabCase" | ||
|
||
class AnonymousStructWithRename(BaseModel): | ||
model_config = ConfigDict(use_enum_values=True) | ||
type: AnonymousStructWithRenameTypes | ||
content: Union[AnonymousStructWithRenameKebabCase, AnonymousStructWithRenameList, AnonymousStructWithRenameLongFieldNames] | ||
Lucretiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@classmethod | ||
def new_anonymous_struct_with_rename_list(cls, list: List[str]): | ||
return cls( | ||
type=AnonymousStructWithRenameTypes.LIST, | ||
content=AnonymousStructWithRenameList(list = list) | ||
) | ||
|
||
|
||
@classmethod | ||
def new_anonymous_struct_with_rename_long_field_names(cls, some_long_field_name: str, and_: bool, but_one_more: List[str]): | ||
return cls( | ||
type=AnonymousStructWithRenameTypes.LONG_FIELD_NAMES, | ||
content=AnonymousStructWithRenameLongFieldNames(some_long_field_name = some_long_field_name, and_ = and_, but_one_more = but_one_more) | ||
) | ||
|
||
|
||
@classmethod | ||
def new_anonymous_struct_with_rename_kebab_case(cls, another_list: List[str], camel_case_string_field: str, something_else: bool): | ||
return cls( | ||
type=AnonymousStructWithRenameTypes.KEBAB_CASE, | ||
content=AnonymousStructWithRenameKebabCase(another_list = another_list, camel_case_string_field = camel_case_string_field, something_else = something_else) | ||
) |
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,74 @@ | ||
""" | ||
Generated by typeshare 1.12.0 | ||
""" | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pydantic import BaseModel, ConfigDict | ||
from typing import Dict, List, 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 AdvancedColors(BaseModel): | ||
model_config = ConfigDict(use_enum_values=True) | ||
t: AdvancedColorsTypes | ||
c: Union[Dict[str, ItemDetailsFieldValue], ItemDetailsFieldValue, List[ItemDetailsFieldValue], List[int], int, str] | ||
Lucretiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@classmethod | ||
def new_advanced_colors_string(cls, c : str): | ||
return cls( | ||
t=AdvancedColorsTypes.STRING, | ||
c=c | ||
) | ||
|
||
|
||
@classmethod | ||
def new_advanced_colors_number(cls, c : int): | ||
return cls( | ||
t=AdvancedColorsTypes.NUMBER, | ||
c=c | ||
) | ||
|
||
|
||
@classmethod | ||
def new_advanced_colors_number_array(cls, c : List[int]): | ||
return cls( | ||
t=AdvancedColorsTypes.NUMBER_ARRAY, | ||
c=c | ||
) | ||
|
||
|
||
@classmethod | ||
def new_advanced_colors_really_cool_type(cls, c : ItemDetailsFieldValue): | ||
return cls( | ||
t=AdvancedColorsTypes.REALLY_COOL_TYPE, | ||
c=c | ||
) | ||
|
||
|
||
@classmethod | ||
def new_advanced_colors_array_really_cool_type(cls, c : List[ItemDetailsFieldValue]): | ||
return cls( | ||
t=AdvancedColorsTypes.ARRAY_REALLY_COOL_TYPE, | ||
c=c | ||
) | ||
|
||
|
||
@classmethod | ||
def new_advanced_colors_dictionary_really_cool_type(cls, c : Dict[str, ItemDetailsFieldValue]): | ||
return cls( | ||
t=AdvancedColorsTypes.DICTIONARY_REALLY_COOL_TYPE, | ||
c=c | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the built-in oncelock https://doc.rust-lang.org/std/sync/struct.OnceLock.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not use the built-in type? https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html