Skip to content

Commit

Permalink
Do not import structs directly, always use full module path instead
Browse files Browse the repository at this point in the history
Summary: This is cleaner and it avoids potential naming conflicts.

Reviewed By: thedavekwon

Differential Revision: D64777526

fbshipit-source-id: 8da04c1a0895edb5781d4ec71361338c45d43160
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Oct 25, 2024
1 parent 806050f commit 74962ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ import thrift.python.types as _fbthrift_python_types
import folly.iobuf as _fbthrift_iobuf

import {{program:module_path}}.thrift_types
from {{program:module_path}}.thrift_types import (
{{#program:structs}}
{{struct:py_name}},
{{/program:structs}}
)

{{#program:structs}}

class {{struct:py_name}}Patch(BaseStructPatch[{{struct:py_name}}]):
class {{struct:py_name}}Patch(BaseStructPatch[{{program:module_path}}.thrift_types.{{struct:py_name}}]):
pass

{{#struct:fields_ordered_by_id}}
@property
def {{field:py_name}}(self) -> OptionalFieldPatch[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,11 @@
import folly.iobuf as _fbthrift_iobuf

import test.fixtures.basic.module.thrift_types
from test.fixtures.basic.module.thrift_types import (
MyStruct,
Containers,
MyDataItem,
MyUnion,
MyException,
MyExceptionWithMessage,
ReservedKeyword,
UnionToBeRenamed,
)


class MyStructPatch(BaseStructPatch[MyStruct]):
class MyStructPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.MyStruct]):
pass

@property
def MyIntField(self) -> OptionalFieldPatch[
int,
Expand Down Expand Up @@ -131,7 +123,9 @@ def no_hack_codegen_field(self) -> OptionalFieldPatch[
9,
_fbthrift_python_types.typeinfo_string)

class ContainersPatch(BaseStructPatch[Containers]):
class ContainersPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.Containers]):
pass

@property
def I32List(self) -> OptionalFieldPatch[
_typing.Sequence[int],
Expand Down Expand Up @@ -163,9 +157,13 @@ def StringToI64Map(self) -> OptionalFieldPatch[
3,
_fbthrift_python_types.MapTypeInfo(_fbthrift_python_types.typeinfo_string, _fbthrift_python_types.typeinfo_i64))

class MyDataItemPatch(BaseStructPatch[MyDataItem]):
class MyDataItemPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.MyDataItem]):
pass


class MyUnionPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.MyUnion]):
pass

class MyUnionPatch(BaseStructPatch[MyUnion]):
@property
def myEnum(self) -> OptionalFieldPatch[
test.fixtures.basic.module.thrift_types.MyEnum,
Expand Down Expand Up @@ -207,7 +205,9 @@ def floatSet(self) -> OptionalFieldPatch[
4,
_fbthrift_python_types.SetTypeInfo(_fbthrift_python_types.typeinfo_float))

class MyExceptionPatch(BaseStructPatch[MyException]):
class MyExceptionPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.MyException]):
pass

@property
def MyIntField(self) -> OptionalFieldPatch[
int,
Expand Down Expand Up @@ -249,7 +249,9 @@ def myUnion(self) -> OptionalFieldPatch[
4,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyUnion))

class MyExceptionWithMessagePatch(BaseStructPatch[MyExceptionWithMessage]):
class MyExceptionWithMessagePatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.MyExceptionWithMessage]):
pass

@property
def MyIntField(self) -> OptionalFieldPatch[
int,
Expand Down Expand Up @@ -291,7 +293,9 @@ def myUnion(self) -> OptionalFieldPatch[
4,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyUnion))

class ReservedKeywordPatch(BaseStructPatch[ReservedKeyword]):
class ReservedKeywordPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.ReservedKeyword]):
pass

@property
def reserved_field(self) -> OptionalFieldPatch[
int,
Expand All @@ -303,7 +307,9 @@ def reserved_field(self) -> OptionalFieldPatch[
1,
_fbthrift_python_types.typeinfo_i32)

class UnionToBeRenamedPatch(BaseStructPatch[UnionToBeRenamed]):
class UnionToBeRenamedPatch(BaseStructPatch[test.fixtures.basic.module.thrift_types.UnionToBeRenamed]):
pass

@property
def reserved_field(self) -> OptionalFieldPatch[
int,
Expand Down

0 comments on commit 74962ff

Please sign in to comment.