diff --git a/thrift/compiler/codemod/add_package_test.py b/thrift/compiler/codemod/add_package_test.py index c49f5a1205a..4db36dc8d93 100644 --- a/thrift/compiler/codemod/add_package_test.py +++ b/thrift/compiler/codemod/add_package_test.py @@ -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", @@ -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", @@ -272,7 +270,6 @@ def test_cpp2_namespace(self): ) def test_empty_namespace(self): - self.write_and_test( "foo.thrift", """\ diff --git a/thrift/compiler/test/fixture_test.py b/thrift/compiler/test/fixture_test.py index b766b981857..cd4a8029b51 100644 --- a/thrift/compiler/test/fixture_test.py +++ b/thrift/compiler/test/fixture_test.py @@ -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.", @@ -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 diff --git a/thrift/compiler/test/fixtures/default_values/tests/default_values_python_test.py b/thrift/compiler/test/fixtures/default_values/tests/default_values_python_test.py index 227ccc5eb24..361bf6cfaa8 100644 --- a/thrift/compiler/test/fixtures/default_values/tests/default_values_python_test.py +++ b/thrift/compiler/test/fixtures/default_values/tests/default_values_python_test.py @@ -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. diff --git a/thrift/lib/py/protocol/TSimpleJSONProtocol.py b/thrift/lib/py/protocol/TSimpleJSONProtocol.py index 3ce9647bb51..d0af3f1c94e 100644 --- a/thrift/lib/py/protocol/TSimpleJSONProtocol.py +++ b/thrift/lib/py/protocol/TSimpleJSONProtocol.py @@ -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() diff --git a/thrift/lib/py/transport/THeaderTransport.py b/thrift/lib/py/transport/THeaderTransport.py index f913809c225..670f0175a58 100644 --- a/thrift/lib/py/transport/THeaderTransport.py +++ b/thrift/lib/py/transport/THeaderTransport.py @@ -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 diff --git a/thrift/lib/py/util/BytesStrIO.py b/thrift/lib/py/util/BytesStrIO.py index 41762322306..b1afe2b16e4 100644 --- a/thrift/lib/py/util/BytesStrIO.py +++ b/thrift/lib/py/util/BytesStrIO.py @@ -19,7 +19,6 @@ import sys if sys.version_info[0] >= 3: - from io import BytesIO class BytesStrIO(BytesIO): diff --git a/thrift/lib/py/util/Decorators.py b/thrift/lib/py/util/Decorators.py index cb779494ddb..37fb8c5df3e 100644 --- a/thrift/lib/py/util/Decorators.py +++ b/thrift/lib/py/util/Decorators.py @@ -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: diff --git a/thrift/lib/py3/metadata.pyi b/thrift/lib/py3/metadata.pyi index ddcf62c71cd..4f3bdc82037 100644 --- a/thrift/lib/py3/metadata.pyi +++ b/thrift/lib/py3/metadata.pyi @@ -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. diff --git a/thrift/lib/py3/reflection.pyi b/thrift/lib/py3/reflection.pyi index fea58a6de37..7bbdb06fa8f 100644 --- a/thrift/lib/py3/reflection.pyi +++ b/thrift/lib/py3/reflection.pyi @@ -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: ... diff --git a/thrift/lib/py3/test/auto_migrate/clients.py b/thrift/lib/py3/test/auto_migrate/clients.py index 77fb9fa99b2..c710a3dcbd6 100644 --- a/thrift/lib/py3/test/auto_migrate/clients.py +++ b/thrift/lib/py3/test/auto_migrate/clients.py @@ -85,7 +85,11 @@ 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): @@ -93,7 +97,11 @@ async def test_none_arguments(self) -> None: 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: @@ -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( diff --git a/thrift/lib/py3/test/auto_migrate/serializer.py b/thrift/lib/py3/test/auto_migrate/serializer.py index f42bee15956..932b412b8f9 100644 --- a/thrift/lib/py3/test/auto_migrate/serializer.py +++ b/thrift/lib/py3/test/auto_migrate/serializer.py @@ -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) diff --git a/thrift/lib/py3_to_python/serializer.py b/thrift/lib/py3_to_python/serializer.py index 5b7bf732594..9bad1bff040 100644 --- a/thrift/lib/py3_to_python/serializer.py +++ b/thrift/lib/py3_to_python/serializer.py @@ -16,7 +16,6 @@ Intermediate solution to be able to have a generic serializer from """ - from enum import Enum from functools import singledispatch diff --git a/thrift/lib/python/capi/test/test_marshal.py b/thrift/lib/python/capi/test/test_marshal.py index 84df470adde..799a223caff 100644 --- a/thrift/lib/python/capi/test/test_marshal.py +++ b/thrift/lib/python/capi/test/test_marshal.py @@ -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) @@ -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(())) @@ -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(())) @@ -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("")) @@ -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())) @@ -268,7 +268,7 @@ 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())) @@ -276,7 +276,7 @@ def make_set(): 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("")) @@ -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)) diff --git a/thrift/lib/python/metadata.py b/thrift/lib/python/metadata.py index 36cfa1a275f..9d88cd34b93 100644 --- a/thrift/lib/python/metadata.py +++ b/thrift/lib/python/metadata.py @@ -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() diff --git a/thrift/lib/python/metadata.pyi b/thrift/lib/python/metadata.pyi index 24d1bc7fc34..797c9ef921f 100644 --- a/thrift/lib/python/metadata.pyi +++ b/thrift/lib/python/metadata.pyi @@ -206,16 +206,16 @@ class ThriftServiceProxy(Protocol): def gen_metadata(cls: Metadata) -> ThriftMetadata: ... @overload def gen_metadata( - cls: Union[StructOrUnion, Type[StructOrUnion]] + cls: Union[StructOrUnion, Type[StructOrUnion]], ) -> ThriftStructProxy: ... @overload def gen_metadata( - cls: Union[GeneratedError, Type[GeneratedError]] + cls: Union[GeneratedError, Type[GeneratedError]], ) -> ThriftExceptionProxy: ... @overload def gen_metadata( # pyre-fixme[11]: Annotation `ServiceInterface` is not defined as a type. - 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. diff --git a/thrift/lib/python/test/client_server.py b/thrift/lib/python/test/client_server.py index 4905d7273d6..556acb65ff6 100644 --- a/thrift/lib/python/test/client_server.py +++ b/thrift/lib/python/test/client_server.py @@ -149,7 +149,6 @@ def setUp(self) -> None: mock_enable_resource_pools_for_python(self.enable_resource_pools_for_python) async def test_get_context(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -178,7 +177,6 @@ async def test_get_context(self) -> None: await handler.getName() async def test_rpc_headers(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -189,7 +187,6 @@ async def test_rpc_headers(self) -> None: self.assertIn("from server", options.read_headers) async def test_server_localhost(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -201,7 +198,6 @@ async def test_server_localhost(self) -> None: await client.takes_a_list([]) async def test_no_client_aexit(self) -> None: - async with TestServer() as sa: ip, port = sa.ip, sa.port assert ip and port @@ -259,7 +255,6 @@ async def test_derived_service(self) -> None: ) async def test_renamed_func(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -352,7 +347,6 @@ async def getName(self) -> str: ) async def test_request_with_default_rpc_options(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -363,7 +357,6 @@ async def test_request_with_default_rpc_options(self) -> None: self.assertEqual(Priority(priority), Priority.N_PRIORITIES) async def test_request_with_specified_rpc_options(self) -> None: - async with TestServer(ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port @@ -421,7 +414,6 @@ def setUp(self) -> None: mock_enable_resource_pools_for_python(self.enable_resource_pools_for_python) async def test_server_localhost(self) -> None: - async with TestServer(handler=StackHandler(), ip="::1") as sa: ip, port = sa.ip, sa.port assert ip and port diff --git a/thrift/lib/python/test/serializer.py b/thrift/lib/python/test/serializer.py index 669da4a6daa..0716824b92a 100644 --- a/thrift/lib/python/test/serializer.py +++ b/thrift/lib/python/test/serializer.py @@ -189,7 +189,7 @@ def test_bad_deserialize(self) -> None: self.serializer.deserialize(self.easy, b"\x05AAAAAAAA") with self.assertRaises(Error): self.serializer.deserialize( - self.easy, b"\x02\xDE\xAD\xBE\xEF", protocol=Protocol.BINARY + self.easy, b"\x02\xde\xad\xbe\xef", protocol=Protocol.BINARY ) def thrift_serialization_round_trip( diff --git a/thrift/lib/python/test/typeinfo_test.py b/thrift/lib/python/test/typeinfo_test.py index e1b83b5da3f..1edba7af285 100644 --- a/thrift/lib/python/test/typeinfo_test.py +++ b/thrift/lib/python/test/typeinfo_test.py @@ -46,7 +46,6 @@ class TypeInfoTests(unittest.TestCase): - @parameterized.expand( [ AdaptedTypeInfo, diff --git a/thrift/test/fuzzer/RandomizerTest.py b/thrift/test/fuzzer/RandomizerTest.py index e299a5cb642..d528444664d 100644 --- a/thrift/test/fuzzer/RandomizerTest.py +++ b/thrift/test/fuzzer/RandomizerTest.py @@ -748,7 +748,6 @@ def testStructContainingDefaultUnion(self): self.assertIsNotNone(val) def testSubRanomizersHaveDefaults(self): - # Have constraints with a field that is never # used and won't come from the existing defaults. # Then make sure that constraint for StructWithOptionals diff --git a/thrift/test/python_capi/capi_test.py b/thrift/test/python_capi/capi_test.py index a2cb95fcae3..aded08067c4 100644 --- a/thrift/test/python_capi/capi_test.py +++ b/thrift/test/python_capi/capi_test.py @@ -236,7 +236,7 @@ def test_roundtrip_enum(self) -> None: def test_roundtrip_field_adapted(self) -> None: a, b = ("TacosSalad", "DaLassoCat") s = StringPair(normal=a, doubled=b) - self.assertEqual(s, fixture.roundtrip_StringPair(s)), + (self.assertEqual(s, fixture.roundtrip_StringPair(s)),) def test_roundtrip_type_adapted(self) -> None: s = DoubledPair(s="TacosSalad", x=42) diff --git a/thrift/test/testset/generator_test.py b/thrift/test/testset/generator_test.py index cff0f1f49dd..3cb75118fb4 100644 --- a/thrift/test/testset/generator_test.py +++ b/thrift/test/testset/generator_test.py @@ -39,7 +39,6 @@ def gen_find_recursive_files(path): class GoldenTest(unittest.TestCase): - MSG = """One or more testset outputs are out of sync with the generator. To sync them, run: thrift/test/testset/generator.py --install_dir ./thrift/test/testset/golden diff --git a/thrift/test/thrift-python/union_test.py b/thrift/test/thrift-python/union_test.py index 585232e46aa..51fc2b3212a 100644 --- a/thrift/test/thrift-python/union_test.py +++ b/thrift/test/thrift-python/union_test.py @@ -415,7 +415,7 @@ def test_adapted_types(self) -> None: with self.assertRaisesRegex( AttributeError, "'str' object has no attribute 'timestamp'" ): - TestUnionAdaptedTypesImmutable.fromValue("1718728839"), + (TestUnionAdaptedTypesImmutable.fromValue("1718728839"),) _thrift_serialization_round_trip(self, immutable_serializer, u2) u3 = TestUnionAdaptedTypesImmutable(non_adapted_i32=1718728839)