diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a50a7230..c605981a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,19 +17,13 @@ repos: exclude: .patch exclude_types: [json] -- repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.1 - hooks: - - id: black - files: \.py$ - args: [--line-length=100] - - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.1.3 hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format - repo: https://github.com/adamchainz/blacken-docs rev: "1.16.0" diff --git a/bson/son.py b/bson/son.py index c5df4e597..cf6271723 100644 --- a/bson/son.py +++ b/bson/son.py @@ -159,7 +159,9 @@ class SON(Dict[_Key, _Value]): if kwargs: self.update(kwargs) - def get(self, key: _Key, default: Optional[Union[_Value, _T]] = None) -> Union[_Value, _T, None]: # type: ignore[override] + def get( # type: ignore[override] + self, key: _Key, default: Optional[Union[_Value, _T]] = None + ) -> Union[_Value, _T, None]: try: return self[key] except KeyError: diff --git a/green_framework_test.py b/green_framework_test.py index 01f72b245..65025798c 100644 --- a/green_framework_test.py +++ b/green_framework_test.py @@ -98,7 +98,8 @@ python {sys.argv[0]} --help-frameworks.""" sys.exit(1) run( - args[0], *args[1:] # Framework name. + args[0], + *args[1:], # Framework name. ) # Command line args to pytest, like what test to run. diff --git a/pymongo/database.py b/pymongo/database.py index 70cdee2dc..75eabc5d3 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -551,7 +551,10 @@ class Database(common.BaseObject, Generic[_DocumentType]): user_fields={"cursor": {"firstBatch": 1}}, ) return self.client._retryable_read( - cmd.get_cursor, cmd.get_read_preference(s), s, retryable=not cmd._performs_write # type: ignore[arg-type] + cmd.get_cursor, + cmd.get_read_preference(s), # type: ignore[arg-type] + s, + retryable=not cmd._performs_write, ) def watch( diff --git a/pymongo/saslprep.py b/pymongo/saslprep.py index 02c845079..c78ad0f0a 100644 --- a/pymongo/saslprep.py +++ b/pymongo/saslprep.py @@ -23,7 +23,8 @@ except ImportError: HAVE_STRINGPREP = False def saslprep( - data: Any, prohibit_unassigned_code_points: Optional[bool] = True # noqa: ARG001 + data: Any, + prohibit_unassigned_code_points: Optional[bool] = True, # noqa: ARG001 ) -> Any: """SASLprep dummy""" if isinstance(data, str): diff --git a/pyproject.toml b/pyproject.toml index b435afb72..8f5fc0741 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -144,7 +144,6 @@ select = [ "C4", # flake8-comprehensions "EM", # flake8-errmsg "ICN", # flake8-import-conventions - "ISC", # flake8-implicit-str-concat "G", # flake8-logging-format "PGH", # pygrep-hooks "PIE", # flake8-pie diff --git a/test/lambda/mongodb/app.py b/test/lambda/mongodb/app.py index 65e6dc88f..5840347d9 100644 --- a/test/lambda/mongodb/app.py +++ b/test/lambda/mongodb/app.py @@ -130,7 +130,12 @@ def create_response(): # Reset the numbers. def reset(): - global open_connections, heartbeat_count, total_heartbeat_duration, total_commands, total_command_duration + global \ + open_connections, \ + heartbeat_count, \ + total_heartbeat_duration, \ + total_commands, \ + total_command_duration open_connections = 0 heartbeat_count = 0 total_heartbeat_duration = 0 diff --git a/test/mod_wsgi_test/test_client.py b/test/mod_wsgi_test/test_client.py index 63ae88347..88eeb7a57 100644 --- a/test/mod_wsgi_test/test_client.py +++ b/test/mod_wsgi_test/test_client.py @@ -131,8 +131,7 @@ def main(options, mode, urls): if options.verbose: print( - "Getting {} {} times total in {} threads, " - "{} times per thread".format( + "Getting {} {} times total in {} threads, " "{} times per thread".format( urls, nrequests_per_thread * options.nthreads, options.nthreads, diff --git a/test/pymongo_mocks.py b/test/pymongo_mocks.py index 2b291c7bd..c750d0cf7 100644 --- a/test/pymongo_mocks.py +++ b/test/pymongo_mocks.py @@ -47,7 +47,7 @@ class MockPool(Pool): assert host_and_port in ( client.mock_standalones + client.mock_members + client.mock_mongoses - ), ("bad host: %s" % host_and_port) + ), "bad host: %s" % host_and_port with Pool.checkout(self, handler) as conn: conn.mock_host = self.mock_host diff --git a/test/test_bson.py b/test/test_bson.py index 749c63bdf..763885e5f 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -783,7 +783,9 @@ class TestBSON(unittest.TestCase): self.assertEqual(0, bson_re1.flags) doc1 = {"r": bson_re1} - doc1_bson = b"\x11\x00\x00\x00\x0br\x00[\\w-\\.]\x00\x00\x00" # document length # r: regex # document terminator + doc1_bson = ( + b"\x11\x00\x00\x00\x0br\x00[\\w-\\.]\x00\x00\x00" + ) # document length # r: regex # document terminator self.assertEqual(doc1_bson, encode(doc1)) self.assertEqual(doc1, decode(doc1_bson)) @@ -794,7 +796,9 @@ class TestBSON(unittest.TestCase): doc2_with_re = {"r": re2} doc2_with_bson_re = {"r": bson_re2} - doc2_bson = b"\x11\x00\x00\x00\x0br\x00.*\x00imsux\x00\x00" # document length # r: regex # document terminator + doc2_bson = ( + b"\x11\x00\x00\x00\x0br\x00.*\x00imsux\x00\x00" + ) # document length # r: regex # document terminator self.assertEqual(doc2_bson, encode(doc2_with_re)) self.assertEqual(doc2_bson, encode(doc2_with_bson_re)) diff --git a/test/test_comment.py b/test/test_comment.py index baac68be5..047bc3f55 100644 --- a/test/test_comment.py +++ b/test/test_comment.py @@ -42,7 +42,12 @@ class Empty: class TestComment(IntegrationTest): def _test_ops( - self, helpers, already_supported, listener, db=Empty(), coll=Empty() # noqa: B008 + self, + helpers, + already_supported, + listener, + db=Empty(), # noqa: B008 + coll=Empty(), # noqa: B008 ): for h, args in helpers: c = "testing comment with " + h.__name__ diff --git a/test/test_encryption.py b/test/test_encryption.py index d034529b4..9de0707e7 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -503,7 +503,10 @@ class TestExplicitSimple(EncryptionIntegrationTest): def test_codec_options(self): with self.assertRaisesRegex(TypeError, "codec_options must be"): ClientEncryption( - KMS_PROVIDERS, "keyvault.datakeys", client_context.client, None # type: ignore[arg-type] + KMS_PROVIDERS, + "keyvault.datakeys", + client_context.client, + None, # type: ignore[arg-type] ) opts = CodecOptions(uuid_representation=UuidRepresentation.JAVA_LEGACY) @@ -1072,7 +1075,9 @@ class TestCorpus(EncryptionIntegrationTest): try: encrypted_val = client_encryption.encrypt( - value["value"], algo, **kwargs # type: ignore[arg-type] + value["value"], + algo, + **kwargs, # type: ignore[arg-type] ) if not value["allowed"]: self.fail(f"encrypt should have failed: {key!r}: {value!r}") diff --git a/test/test_monitoring.py b/test/test_monitoring.py index 6880a30dc..26a1da3f8 100644 --- a/test/test_monitoring.py +++ b/test/test_monitoring.py @@ -1191,7 +1191,9 @@ class TestEventClasses(unittest.TestCase): ) delta = 0.1 event = monitoring.ServerHeartbeatSucceededEvent( - delta, {"ok": 1}, connection_id # type: ignore[arg-type] + delta, + {"ok": 1}, # type: ignore[arg-type] + connection_id, ) self.assertEqual( repr(event), @@ -1199,7 +1201,9 @@ class TestEventClasses(unittest.TestCase): "duration: 0.1, awaited: False, reply: {'ok': 1}>", ) event = monitoring.ServerHeartbeatFailedEvent( - delta, "ERROR", connection_id # type: ignore[arg-type] + delta, + "ERROR", # type: ignore[arg-type] + connection_id, ) self.assertEqual( repr(event), @@ -1216,7 +1220,10 @@ class TestEventClasses(unittest.TestCase): "", ) event = monitoring.ServerDescriptionChangedEvent( - "PREV", "NEW", server_address, topology_id # type: ignore[arg-type] + "PREV", # type: ignore[arg-type] + "NEW", # type: ignore[arg-type] + server_address, + topology_id, ) self.assertEqual( repr(event), @@ -1233,7 +1240,9 @@ class TestEventClasses(unittest.TestCase): event = monitoring.TopologyOpenedEvent(topology_id) self.assertEqual(repr(event), "") event = monitoring.TopologyDescriptionChangedEvent( - "PREV", "NEW", topology_id # type: ignore[arg-type] + "PREV", # type: ignore[arg-type] + "NEW", # type: ignore[arg-type] + topology_id, ) self.assertEqual( repr(event), diff --git a/test/test_sdam_monitoring_spec.py b/test/test_sdam_monitoring_spec.py index 6e6a07cd6..105ffaf03 100644 --- a/test/test_sdam_monitoring_spec.py +++ b/test/test_sdam_monitoring_spec.py @@ -83,8 +83,9 @@ def compare_events(expected_dict, actual): if expected["address"] != "{}:{}".format(*actual.server_address): return ( False, - "ServerOpeningEvent published with wrong address (expected" - " {}, got {}".format(expected["address"], actual.server_address), + "ServerOpeningEvent published with wrong address (expected" " {}, got {}".format( + expected["address"], actual.server_address + ), ) elif expected_type == "server_description_changed_event": @@ -93,8 +94,9 @@ def compare_events(expected_dict, actual): if expected["address"] != "{}:{}".format(*actual.server_address): return ( False, - "ServerDescriptionChangedEvent has wrong address" - " (expected {}, got {}".format(expected["address"], actual.server_address), + "ServerDescriptionChangedEvent has wrong address" " (expected {}, got {}".format( + expected["address"], actual.server_address + ), ) if not compare_server_descriptions(expected["newDescription"], actual.new_description): @@ -113,8 +115,9 @@ def compare_events(expected_dict, actual): if expected["address"] != "{}:{}".format(*actual.server_address): return ( False, - "ServerClosedEvent published with wrong address" - " (expected {}, got {}".format(expected["address"], actual.server_address), + "ServerClosedEvent published with wrong address" " (expected {}, got {}".format( + expected["address"], actual.server_address + ), ) elif expected_type == "topology_opening_event": diff --git a/test/test_ssl.py b/test/test_ssl.py index bde385138..3b307df39 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -447,7 +447,8 @@ class TestSSL(IntegrationTest): # Server cert and hostname are verified. connected( MongoClient( - "mongodb://localhost/?ssl=true&serverSelectionTimeoutMS=1000", **self.credentials # type: ignore[arg-type] + "mongodb://localhost/?ssl=true&serverSelectionTimeoutMS=1000", + **self.credentials, # type: ignore[arg-type] ) ) diff --git a/test/test_topology.py b/test/test_topology.py index 88c99d2a2..3ee33afab 100644 --- a/test/test_topology.py +++ b/test/test_topology.py @@ -452,7 +452,9 @@ class TestMultiServerTopology(TopologyTest): # Discovering a replica set without the setName supplied by the user # is not yet supported by MongoClient, but Topology can do it. topology_settings = SetNameDiscoverySettings( - seeds=[address], pool_class=MockPool, monitor_class=DummyMonitor # type: ignore[arg-type] + seeds=[address], + pool_class=MockPool, # type: ignore[arg-type] + monitor_class=DummyMonitor, # type: ignore[arg-type] ) t = Topology(topology_settings) @@ -480,7 +482,9 @@ class TestMultiServerTopology(TopologyTest): # Discovering a replica set without the setName supplied by the user # is not yet supported by MongoClient, but Topology can do it. topology_settings = SetNameDiscoverySettings( - seeds=[address], pool_class=MockPool, monitor_class=DummyMonitor # type: ignore[arg-type] + seeds=[address], + pool_class=MockPool, # type: ignore[arg-type] + monitor_class=DummyMonitor, # type: ignore[arg-type] ) t = Topology(topology_settings) diff --git a/test/unified_format.py b/test/unified_format.py index 0fcabcc70..99758989c 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -1404,8 +1404,9 @@ class UnifiedSpecTestMixinV1(IntegrationTest): session = self.entity_map[spec["session"]] if not session._pinned_address: self.fail( - "Cannot use targetedFailPoint operation with unpinned " - "session {}".format(spec["session"]) + "Cannot use targetedFailPoint operation with unpinned " "session {}".format( + spec["session"] + ) ) client = single_client("{}:{}".format(*session._pinned_address)) diff --git a/tox.ini b/tox.ini index 7e889dff2..bbf2307d9 100644 --- a/tox.ini +++ b/tox.ini @@ -156,8 +156,6 @@ deps = https://github.com/ajdavis/mongo-mockup-db/archive/master.zip extras = {[testenv:test]extras} -allowlist_externals = - .evergreen/check-c-extensions.sh passenv = * allowlist_externals = {[testenv:test]allowlist_externals}