Skip to content

Commit

Permalink
Convert directory fbcode/thrift to use the Ruff Formatter
Browse files Browse the repository at this point in the history
Summary:
Converts the directory specified to use the Ruff formatter in pyfmt

ruff_dog

If this diff causes merge conflicts when rebasing, please run
`hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt`
on your diff, and amend any changes before rebasing onto latest.
That should help reduce or eliminate any merge conflicts.

allow-large-files

Reviewed By: amyreese

Differential Revision: D64119455

fbshipit-source-id: 2623f508ce8b2faf369de22d5082552a15bcd397
  • Loading branch information
Thomas Polasek authored and facebook-github-bot committed Oct 10, 2024
1 parent b4c8f5c commit 36eefac
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 103 deletions.
3 changes: 0 additions & 3 deletions thrift/compiler/codemod/add_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def test_package_from_namespace(self):
)

def test_with_common_namespace(self):

# When domain is present but not in the common package, correctly uses the domain present in file
self.write_and_test(
"foo.thrift",
Expand Down Expand Up @@ -210,7 +209,6 @@ def test_with_common_identifiers(self):
)

def test_with_longest_pkg(self):

# When minimum length is not met, use the longest path.
self.write_and_test(
"foo.thrift",
Expand Down Expand Up @@ -272,7 +270,6 @@ def test_cpp2_namespace(self):
)

def test_empty_namespace(self):

self.write_and_test(
"foo.thrift",
"""\
Expand Down
2 changes: 0 additions & 2 deletions thrift/compiler/test/fixture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _gen_find_recursive_files(top: Path) -> typing.Generator[Path, None, None]:


class FixtureTest(unittest.TestCase):

MSG = " ".join(
[
"One or more fixtures are out of sync with the thrift compiler.",
Expand Down Expand Up @@ -107,7 +106,6 @@ def setUp(self) -> None:
self.maxDiff = None

def runTest(self, fixture_name: str) -> None:

repo_root_dir_abspath = Path.cwd()
fixture_dir_abspath = (
repo_root_dir_abspath / _FIXTURES_ROOT_DIR_RELPATH / fixture_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class ThriftPythonDefaultValuesTest(unittest.TestCase):

def test_intrinsic_default_values(self) -> None:
"""
Tests intrinsic (i.e., non-custom) default values for struct fields.
Expand Down
102 changes: 50 additions & 52 deletions thrift/lib/py/protocol/TSimpleJSONProtocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,58 +48,56 @@
THRIFT_INFINITY = b"Infinity"
THRIFT_NEGATIVE_INFINITY = b"-Infinity"

JSON_CHAR_TABLE = (
[ # 0 1 2 3 4 5 6 7 8 9 A B C D E F
0,
0,
0,
0,
0,
0,
0,
0,
b"b",
b"t",
b"n",
0,
b"f",
b"r",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
b'"',
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]
)
JSON_CHAR_TABLE = [ # 0 1 2 3 4 5 6 7 8 9 A B C D E F
0,
0,
0,
0,
0,
0,
0,
0,
b"b",
b"t",
b"n",
0,
b"f",
b"r",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
b'"',
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]


JSON_CHARS_TO_ESCAPE = set()
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/py/transport/THeaderTransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ def _frame_size_check(sz, set_max_size, header: bool = True) -> None:


class RequestHandler(http_server.BaseHTTPRequestHandler):

# Same as superclass function, but append 'POST' because we
# stripped it in the calling function. Would be nice if
# we had an ungetch instead
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/py/util/BytesStrIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import sys

if sys.version_info[0] >= 3:

from io import BytesIO

class BytesStrIO(BytesIO):
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/py/util/Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def nested(self, iprot, oprot, server_ctx=None):


def write_result(result, reply_type, seqid, event_handler, handler_ctx, fn_name, oprot):

event_handler.preWrite(handler_ctx, fn_name, result)

try:
Expand Down
4 changes: 2 additions & 2 deletions thrift/lib/py3/metadata.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ def gen_metadata(cls: Metadata) -> ThriftMetadata: ...
def gen_metadata(cls: Union[Struct, Type[Struct]]) -> ThriftStructProxy: ...
@overload
def gen_metadata(
cls: Union[GeneratedError, Type[GeneratedError]]
cls: Union[GeneratedError, Type[GeneratedError]],
) -> ThriftExceptionProxy: ...
@overload
def gen_metadata(
cls: Union[ServiceInterface, Type[ServiceInterface], Client, Type[Client]]
cls: Union[ServiceInterface, Type[ServiceInterface], Client, Type[Client]],
) -> ThriftServiceProxy: ...
@overload
# pyre-fixme[43]: Signature of overloaded function `gen_metadata` will never be matched.
Expand Down
4 changes: 2 additions & 2 deletions thrift/lib/py3/reflection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ TClient = TypeVar("TClient", bound=Client)
def inspect(cls: Union[Struct, Type[Struct], Error, Type[Error]]) -> StructSpec: ...
@overload
def inspect(
cls: Union[ServiceInterface, Type[ServiceInterface], TClient, Type[TClient]]
cls: Union[ServiceInterface, Type[ServiceInterface], TClient, Type[TClient]],
) -> InterfaceSpec: ...
@overload
def inspect(
# pyre-ignore[2] : it may return anything
cls: Union[Sequence[Any], Type[Sequence[Any]]]
cls: Union[Sequence[Any], Type[Sequence[Any]]],
) -> ListSpec: ...
@overload
def inspect(cls: Union[Set[Any], Type[Set[Any]]]) -> SetSpec: ...
Expand Down
27 changes: 23 additions & 4 deletions thrift/lib/py3/test/auto_migrate/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,23 @@ async def test_none_arguments(self) -> None:
with self.assertRaises(TypeError):
await client.take_it_easy(9) # pyre-ignore[20] testing bad behaviour
with self.assertRaises(TypeError):
await client.take_it_easy(9, None) # pyre-ignore[6] testing bad behaviour
await client.take_it_easy(
9,
# pyre-fixme[6]: For 2nd argument expected `easy` but got `None`.
None,
)
with self.assertRaises(TypeError):
await client.takes_a_list(None) # pyre-ignore[6] testing bad behaviour
with self.assertRaises(TypeError):
await client.invert(None) # pyre-ignore[6] testing bad behaviour
with self.assertRaises(TypeError):
await client.pick_a_color(None) # pyre-ignore[6] testing bad behaviour
with self.assertRaises(TypeError):
await client.take_it_easy(None, easy()) # pyre-ignore[6] testing bad behaviour
await client.take_it_easy(
# pyre-fixme[6]: For 1st argument expected `int` but got `None`.
None,
easy(),
)

@brokenInAutoMigrate() # Exceptions aren't unified
def test_bad_unix_domain_socket_raises_TransportError_on_connection(self) -> None:
Expand Down Expand Up @@ -152,14 +160,25 @@ async def test_rpc_container_autoboxing(self) -> None:
await client.takes_a_list(I32List([1, 2, 3]))

with self.assertRaises(TypeError):
await client.takes_a_list([1, "b", "three"]) # pyre-ignore[6] testing bad behaviour
await client.takes_a_list(
# pyre-fixme[6]: For 1st argument expected `Sequence[int]` but
# got `Sequence[Union[int, str]]`.
[1, "b", "three"]
)

async def test_rpc_non_container_types(self) -> None:
async with ClientEventHandlerTestHelper().get_async_client(
TestingService, port=1
) as client:
with self.assertRaises(TypeError):
await client.complex_action(b"foo", "bar", "nine", fourth="baz") # pyre-ignore[6] testing bad behaviour
await client.complex_action(
# pyre-fixme[6]: For 1st argument expected `str` but got `bytes`.
b"foo",
"bar",
# pyre-fixme[6]: For 3rd argument expected `int` but got `str`.
"nine",
fourth="baz",
)

async def test_rpc_enum_args(self) -> None:
async with ClientEventHandlerTestHelper().get_async_client(
Expand Down
4 changes: 2 additions & 2 deletions thrift/lib/py3/test/auto_migrate/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def test_bad_deserialize(self) -> None:
with self.assertRaises(Error):
deserialize(easy, b"\x05AAAAAAAA")
with self.assertRaises(Error):
deserialize(easy, b"\x02\xDE\xAD\xBE\xEF", protocol=Protocol.BINARY)
deserialize(easy, b"\x02\xde\xad\xbe\xef", protocol=Protocol.BINARY)
with self.assertRaises(BufferError):
deserialize_from_header(easy, b"\x02\xDE\xAD\xBE\xEF")
deserialize_from_header(easy, b"\x02\xde\xad\xbe\xef")
control = easy(val=5, val_list=[4, 3, 2, 1])
buf = serialize_with_header(control, transform=Transform.ZSTD_TRANSFORM)
newBytes = bytearray(buf)
Expand Down
1 change: 0 additions & 1 deletion thrift/lib/py3_to_python/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Intermediate solution to be able to have a generic serializer from
"""


from enum import Enum
from functools import singledispatch

Expand Down
26 changes: 13 additions & 13 deletions thrift/lib/python/capi/test/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,27 @@ def test_bool(self) -> None:
self.assert_type_error(fixture.roundtrip_bool, None, "oops", 1, 1.0)

def test_bytes(self) -> None:
for x in (b"", b"bytes", b"\xE2\x82\xAC"):
for x in (b"", b"bytes", b"\xe2\x82\xac"):
self.assertEqual(x, fixture.roundtrip_bytes(x))
self.assert_type_error(fixture.roundtrip_bytes, None, "oops", 1, 1.0)

def test_unicode(self) -> None:
for x in ("", "unicode", b"\xE2\x82\xAC".decode()):
for x in ("", "unicode", b"\xe2\x82\xac".decode()):
self.assertEqual(x, fixture.roundtrip_unicode(x))
self.assert_type_error(fixture.roundtrip_unicode, None, b"oops", 1, 1.0)

self.assertEqual("€", fixture.make_unicode(b"\xE2\x82\xAC"))
self.assertEqual("€", fixture.make_unicode(b"\xe2\x82\xac"))
with self.assertRaises(UnicodeDecodeError):
fixture.make_unicode(b"\xE2\x82")
fixture.make_unicode(b"\xe2\x82")

def test_iobuf_stack(self) -> None:
for b in (b"", b"bytes", b"\xE2\x82\xAC"):
for b in (b"", b"bytes", b"\xe2\x82\xac"):
x = IOBuf(memoryview(b))
self.assertEqual(x, fixture.roundtrip_iobuf_stack(x))
self.assert_type_error(fixture.roundtrip_iobuf_stack, None, b"oops", 1, 1.0)

def test_iobuf_heap(self) -> None:
for b in (b"", b"bytes", b"\xE2\x82\xAC"):
for b in (b"", b"bytes", b"\xe2\x82\xac"):
x = IOBuf(memoryview(b))
self.assertEqual(x, fixture.roundtrip_iobuf_heap(x))
self.assert_type_error(fixture.roundtrip_iobuf_heap, None, b"oops", 1, 1.0)
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_bytes_list(self) -> None:
empty_tuple_refcount = getrefcount(())

def make_list():
return (b"", b"-1", b"wef2", b"\xE2\x82\xAC")
return (b"", b"-1", b"wef2", b"\xe2\x82\xac")

self.assertEqual(make_list(), fixture.roundtrip_bytes_list(make_list()))
self.assertEqual((), fixture.roundtrip_bytes_list(()))
Expand All @@ -204,7 +204,7 @@ def test_unicode_list(self) -> None:
empty_tuple_refcount = getrefcount(())

def make_list():
return ("", "-1", "€", "", b"\xE2\x82\xAC".decode())
return ("", "-1", "€", "", b"\xe2\x82\xac".decode())

self.assertEqual(make_list(), fixture.roundtrip_unicode_list(make_list()))
self.assertEqual((), fixture.roundtrip_unicode_list(()))
Expand All @@ -213,7 +213,7 @@ def make_list():
self.assertEqual(empty_tuple_refcount, getrefcount(()))

with self.assertRaises(UnicodeDecodeError):
fixture.make_unicode_list((b"", b"", b"", b"", b"\xE2\x82"))
fixture.make_unicode_list((b"", b"", b"", b"", b"\xe2\x82"))
# The empty str created before error are not leaked
self.assertEqual(empty_refcount, getrefcount(""))

Expand Down Expand Up @@ -256,7 +256,7 @@ def test_bytes_set(self) -> None:
empty_refcount = getrefcount(b"")

def make_set():
return frozenset({b"", b"-1", b"wef2", b"\xE2\x82\xAC"})
return frozenset({b"", b"-1", b"wef2", b"\xe2\x82\xac"})

self.assertEqual(make_set(), fixture.roundtrip_bytes_set(make_set()))
self.assertEqual(frozenset(), fixture.roundtrip_bytes_set(frozenset()))
Expand All @@ -268,15 +268,15 @@ def test_unicode_set(self) -> None:
empty_refcount = getrefcount("")

def make_set():
return frozenset({"", "-1", "€", b"\xE2\x82\xAC".decode()})
return frozenset({"", "-1", "€", b"\xe2\x82\xac".decode()})

self.assertEqual(make_set(), fixture.roundtrip_unicode_set(make_set()))
self.assertEqual(frozenset(), fixture.roundtrip_unicode_set(frozenset()))
# no leaks!
self.assertEqual(empty_refcount, getrefcount(""))

with self.assertRaises(UnicodeDecodeError):
fixture.make_unicode_set(frozenset((b"", b"a", b"c", b"e", b"\xE2\x82")))
fixture.make_unicode_set(frozenset((b"", b"a", b"c", b"e", b"\xe2\x82")))
# The empty str created before error are not leaked
self.assertEqual(empty_refcount, getrefcount(""))

Expand Down Expand Up @@ -401,7 +401,7 @@ def make_dict():
self.assertEqual(ace_refcount, getrefcount(1))

with self.assertRaises(UnicodeDecodeError):
fixture.make_unicode_val_map(((-1, b""), (0, b"a"), (1, b"\xE2\x82")))
fixture.make_unicode_val_map(((-1, b""), (0, b"a"), (1, b"\xe2\x82")))

self.assertEqual(nil_refcount, getrefcount(0))
self.assertEqual(int_refcount, getrefcount(-1))
Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/python/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def gen_metadata(
Type[GeneratedError],
ServiceInterface,
Type[ServiceInterface],
]
],
) -> Union[ThriftStructProxy, ThriftExceptionProxy, ThriftServiceProxy]:
if hasattr(obj_or_cls, "getThriftModuleMetadata"):
return obj_or_cls.getThriftModuleMetadata()
Expand Down
Loading

0 comments on commit 36eefac

Please sign in to comment.