Skip to content

Commit

Permalink
Fix python stubs in fbcode/thrift/lib/python/mutable_converter.pyi
Browse files Browse the repository at this point in the history
Reviewed By: yoney

Differential Revision: D66863183

fbshipit-source-id: 7376b1e6748ab7d00ffea67d66e542532693370b
  • Loading branch information
Aristidis Papaioannou authored and facebook-github-bot committed Dec 6, 2024
1 parent c83e0a6 commit 556de86
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions third-party/thrift/src/thrift/lib/python/mutable_converter.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@
import typing

from thrift.py3.types import Struct as Py3Struct
from thrift.python.mutable_types import MutableStructOrUnion as PythonMutableStruct
from thrift.python.types import StructOrUnion as PythonStruct
from thrift.python.mutable_types import (
MutableStructOrUnion as PythonMutableStructOrUnion,
)
from thrift.python.types import StructOrUnion as PythonImmutableStructOrUnion

# thrift-py-deprecated struct doesn't have a base class,
# thus this hacky way to do type checking
class PyDeprecatedStruct(typing.Protocol):
# pyre-ignore[4]: Attribute annotation cannot be `Any`.
thrift_spec: typing.Any

T = typing.TypeVar("T", bound=PythonStruct)
TObj = PythonStruct | PythonMutableStruct | Py3Struct | PyDeprecatedStruct
T = typing.TypeVar("T", bound=PythonMutableStructOrUnion)
TObj = (
PythonImmutableStructOrUnion
| PythonMutableStructOrUnion
| Py3Struct
| PyDeprecatedStruct
)

@typing.overload
def to_python_struct(cls: typing.Type[T], obj: TObj) -> T: ...
def to_mutable_python_struct_or_union(
mutable_thrift_python_cls: typing.Type[T], src_struct_or_union: TObj
) -> T: ...
@typing.overload
def to_python_struct(
cls: typing.Type[T], obj: typing.Optional[TObj]
def to_mutable_python_struct_or_union(
mutable_thrift_python_cls: typing.Type[T],
src_struct_or_union: typing.Optional[TObj],
) -> typing.Optional[T]: ...

0 comments on commit 556de86

Please sign in to comment.