diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 503b10e2..184110fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v3.17.0 hooks: - id: pyupgrade - args: ["--py37-plus", "--keep-runtime-typing"] + args: ["--py38-plus"] - repo: https://github.com/PyCQA/autoflake rev: v2.3.1 @@ -20,7 +20,14 @@ repos: rev: v1.5.0 hooks: - id: yesqa - exclude: ^kombu/messaging\.py$|^kombu/serialization\.py$ + + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell # See pyproject.toml for args + args: [--toml, pyproject.toml, --write-changes] + additional_dependencies: + - tomli - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 @@ -34,3 +41,9 @@ repos: rev: 5.13.2 hooks: - id: isort + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.11.2 + hooks: + - id: mypy + pass_filenames: false diff --git a/Makefile b/Makefile index 93982c3b..978b137f 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ help: @echo "readme - Regenerate README.rst file." @echo "contrib - Regenerate CONTRIBUTING.rst file" @echo "clean-dist --------- - Clean all distribution build artifacts." - @echo " clean-git-force - Remove all uncomitted files." + @echo " clean-git-force - Remove all uncommitted files." @echo " clean ------------ - Non-destructive clean" @echo " clean-pyc - Remove .pyc/__pycache__ files" @echo " clean-docs - Remove documentation build artifacts." diff --git a/examples/simple_receive.py b/examples/simple_receive.py index c2512cca..1c967165 100644 --- a/examples/simple_receive.py +++ b/examples/simple_receive.py @@ -23,7 +23,7 @@ with Connection('amqp://guest:guest@localhost:5672//') as conn: print(message.payload) #### -#: If you don't use the with statement then you must aways +#: If you don't use the with statement then you must always # remember to close objects after use: # queue.close() # connection.close() diff --git a/kombu/asynchronous/aws/sqs/connection.py b/kombu/asynchronous/aws/sqs/connection.py index 2592e1af..03061622 100644 --- a/kombu/asynchronous/aws/sqs/connection.py +++ b/kombu/asynchronous/aws/sqs/connection.py @@ -78,7 +78,7 @@ class AsyncSQSConnection(AsyncAWSQueryConnection): def make_request(self, operation_name, params, queue_url, verb, callback=None): # noqa """ - Overide make_request to support different protocols. + Override make_request to support different protocols. botocore is soon going to change the default protocol of communicating with SQS backend from 'query' to 'json', so we need a special diff --git a/kombu/matcher.py b/kombu/matcher.py index a4d71bb1..fa0c5850 100644 --- a/kombu/matcher.py +++ b/kombu/matcher.py @@ -89,7 +89,7 @@ registry = MatcherRegistry() :param data: The data that should be matched. Must be string. :param pattern: The pattern that should be applied. Must be string. - :keyword matcher: An optional string representing the mathcing + :keyword matcher: An optional string representing the matching method (for example, `glob` or `pcre`). If :const:`None` (default), then `glob` will be used. @@ -108,7 +108,7 @@ match = registry.match .. function:: register(name, matcher): Register a new matching method. - :param name: A convenient name for the mathing method. + :param name: A convenient name for the matching method. :param matcher: A method that will be passed data and pattern. """ register = registry.register diff --git a/kombu/messaging.py b/kombu/messaging.py index ef6a6767..588e8a26 100644 --- a/kombu/messaging.py +++ b/kombu/messaging.py @@ -51,7 +51,7 @@ class Producer: #: Default compression method. Disabled by default. compression = None - #: By default, if a defualt exchange is set, + #: By default, if a default exchange is set, #: that exchange will be declare when publishing a message. auto_declare = True diff --git a/kombu/resource.py b/kombu/resource.py index d911587a..4a521a26 100644 --- a/kombu/resource.py +++ b/kombu/resource.py @@ -93,7 +93,7 @@ class Resource: # not evaluated yet, just put it back self._resource.put_nowait(R) else: - # evaluted so must try to release/close first. + # evaluated so must try to release/close first. self.release(R) raise self._dirty.add(R) diff --git a/kombu/transport/azureservicebus.py b/kombu/transport/azureservicebus.py index 2a899027..01de80a5 100644 --- a/kombu/transport/azureservicebus.py +++ b/kombu/transport/azureservicebus.py @@ -59,7 +59,7 @@ from __future__ import annotations import string from queue import Empty -from typing import Any, Dict, Set +from typing import Any import azure.core.exceptions import azure.servicebus.exceptions @@ -122,8 +122,8 @@ class Channel(virtual.Channel): # Max time to backoff (is the default from service bus repo) default_retry_backoff_max: int = 120 domain_format: str = 'kombu%(vhost)s' - _queue_cache: Dict[str, SendReceive] = {} - _noack_queues: Set[str] = set() + _queue_cache: dict[str, SendReceive] = {} + _noack_queues: set[str] = set() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/kombu/transport/azurestoragequeues.py b/kombu/transport/azurestoragequeues.py index 16d22f0b..1a411f4f 100644 --- a/kombu/transport/azurestoragequeues.py +++ b/kombu/transport/azurestoragequeues.py @@ -54,7 +54,7 @@ from __future__ import annotations import string from queue import Empty -from typing import Any, Optional +from typing import Any from azure.core.exceptions import ResourceExistsError @@ -87,7 +87,7 @@ class Channel(virtual.Channel): """Azure Storage Queues channel.""" domain_format: str = 'kombu%(vhost)s' - _queue_service: Optional[QueueServiceClient] = None + _queue_service: QueueServiceClient | None = None _queue_name_cache: dict[Any, Any] = {} no_ack: bool = True _noack_queues: set[Any] = set() @@ -201,7 +201,7 @@ class Transport(virtual.Transport): Channel = Channel polling_interval: int = 1 - default_port: Optional[int] = None + default_port: int | None = None can_parse_url: bool = True @staticmethod diff --git a/kombu/transport/pyamqp.py b/kombu/transport/pyamqp.py index c8fd3c86..052043da 100644 --- a/kombu/transport/pyamqp.py +++ b/kombu/transport/pyamqp.py @@ -58,7 +58,7 @@ All parameters are passed to ``ssl`` parameter of :class:`amqp.connection.Connection` class. SSL option ``server_hostname`` can be set to ``None`` which is causing using -hostname from broker URL. This is usefull when failover is used to fill +hostname from broker URL. This is useful when failover is used to fill ``server_hostname`` with currently used broker:: conn = Connect('amqp://broker1.example.com;broker2.example.com', ssl={ diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index 5879f7a4..48e01a83 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -356,7 +356,7 @@ class QoS(virtual.QoS): def append(self, message, delivery_tag): delivery = message.delivery_info EX, RK = delivery['exchange'], delivery['routing_key'] - # TODO: Remove this once we soley on Redis-py 3.0.0+ + # TODO: Remove this once we solely on Redis-py 3.0.0+ if redis.VERSION[0] >= 3: # Redis-py changed the format of zadd args in v3.0.0 zadd_args = [{delivery_tag: time()}] @@ -747,7 +747,7 @@ class Channel(virtual.Channel): raise self.connection.cycle.add(self) # add to channel poller. - # and set to true after sucessfuly added channel to the poll. + # and set to true after successfully added channel to the poll. self._registered = True # copy errors, in case channel closed but threads still diff --git a/kombu/utils/debug.py b/kombu/utils/debug.py index 7889ed47..05d31b71 100644 --- a/kombu/utils/debug.py +++ b/kombu/utils/debug.py @@ -11,7 +11,7 @@ from kombu.log import get_logger if TYPE_CHECKING: from logging import Logger - from typing import Any, Callable, Dict, List, Optional + from typing import Any, Callable from kombu.transport.base import Transport @@ -19,8 +19,8 @@ __all__ = ('setup_logging', 'Logwrapped') def setup_logging( - loglevel: Optional[int] = logging.DEBUG, - loggers: Optional[List[str]] = None + loglevel: int | None = logging.DEBUG, + loggers: list[str] | None = None ) -> None: """Setup logging to stdout.""" loggers = ['kombu.connection', 'kombu.channel'] if not loggers else loggers @@ -38,8 +38,8 @@ class Logwrapped: def __init__( self, instance: Transport, - logger: Optional[Logger] = None, - ident: Optional[str] = None + logger: Logger | None = None, + ident: str | None = None ): self.instance = instance self.logger = get_logger(logger) @@ -52,7 +52,7 @@ class Logwrapped: return meth @wraps(meth) - def __wrapped(*args: List[Any], **kwargs: Dict[str, Any]) -> Callable: + def __wrapped(*args: list[Any], **kwargs: dict[str, Any]) -> Callable: info = '' if self.ident: info += self.ident.format(self.instance) @@ -73,5 +73,5 @@ class Logwrapped: def __repr__(self) -> str: return repr(self.instance) - def __dir__(self) -> List[str]: + def __dir__(self) -> list[str]: return dir(self.instance) diff --git a/kombu/utils/scheduling.py b/kombu/utils/scheduling.py index e4bff7b4..d5d8a7f4 100644 --- a/kombu/utils/scheduling.py +++ b/kombu/utils/scheduling.py @@ -54,7 +54,7 @@ class FairCycle: try: return self.fun(resource, callback, **kwargs) except self.predicate: - # reraise when retries exchausted. + # reraise when retries exhausted. if tried >= len(self.resources) - 1: raise diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..591b14b0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[tool.codespell] +ignore-words-list = "assertin" +skip = "./.*,docs/AUTHORS.txt,docs/history/*,docs/spelling_wordlist.txt,Changelog.rst,CONTRIBUTORS.txt,*.key" + +[tool.coverage.run] +branch = true +cover_pylib = false +include = ["*kombu/*"] +omit = ["kombu.tests.*"] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "if TYPE_CHECKING:", + "except ImportError:" +] +omit = [ + "*/python?.?/*", + "*/site-packages/*", + "*/pypy/*", + "*kombu/utils/debug.py", +] diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 4f1b71d8..25cee80b 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -163,7 +163,7 @@ class test_Connection: conn._ensure_connection = Mock() conn.connect() - # ensure_connection must be called to return immidiately + # ensure_connection must be called to return immediately # and fail with transport exception conn._ensure_connection.assert_called_with( max_retries=1, reraise_as_library_errors=False @@ -182,7 +182,7 @@ class test_Connection: conn.connect() # connect() is ignoring transport options - # ensure_connection must be called to return immidiately + # ensure_connection must be called to return immediately # and fail with transport exception conn._ensure_connection.assert_called_with( max_retries=1, reraise_as_library_errors=False diff --git a/t/unit/transport/test_SQS.py b/t/unit/transport/test_SQS.py index 8edc61ce..2a70d464 100644 --- a/t/unit/transport/test_SQS.py +++ b/t/unit/transport/test_SQS.py @@ -1005,5 +1005,5 @@ class test_Channel: ) output_message = self.queue(self.channel).get() assert message == output_message.payload - # It's not propogated to the properties + # It's not propagated to the properties assert 'message_attributes' not in output_message.properties diff --git a/t/unit/transport/test_azureservicebus.py b/t/unit/transport/test_azureservicebus.py index 9488e9ca..7c181283 100644 --- a/t/unit/transport/test_azureservicebus.py +++ b/t/unit/transport/test_azureservicebus.py @@ -118,7 +118,7 @@ def test_queue_service_nocredentials(): def test_queue_service_sas(): - # Test gettings queue service without credentials + # Test getting queue service without credentials conn = Connection(URL_CREDS_SAS, transport=azureservicebus.Transport) with patch('kombu.transport.azureservicebus.ServiceBusClient') as m: channel = conn.channel() diff --git a/t/unit/transport/test_azurestoragequeues.py b/t/unit/transport/test_azurestoragequeues.py index 0c9ef32a..3657e7c5 100644 --- a/t/unit/transport/test_azurestoragequeues.py +++ b/t/unit/transport/test_azurestoragequeues.py @@ -28,7 +28,7 @@ def test_queue_service_nocredentials(): def test_queue_service(): - # Test gettings queue service without credentials + # Test getting queue service without credentials conn = Connection(URL_CREDS, transport=azurestoragequeues.Transport) with patch('kombu.transport.azurestoragequeues.QueueServiceClient'): channel = conn.channel() diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index 778d1804..2f4d8951 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -392,11 +392,11 @@ class test_Channel: # the connection was added to the cycle conn.transport.cycle.add.assert_called_once() assert len(conn.transport.channels) == 1 - # the channel was flaged as registered into poller + # the channel was flagged as registered into poller assert chan._registered def test_redis_on_disconnect_channel_only_if_was_registered(self): - """Test shoud check if the _on_disconnect method is called only + """Test should check if the _on_disconnect method is called only if the channel was registered into the poller.""" # given: mock pool and client pool = Mock(name='pool') @@ -437,7 +437,7 @@ class test_Channel: transport_options={}, hostname="127.0.0.1", virtual_host=None))) - # create the _connparams with overriden connection_class + # create the _connparams with overridden connection_class connparams = chan._connparams(asynchronous=True) # create redis.Connection redis_connection = connparams['connection_class']() @@ -498,7 +498,7 @@ class test_Channel: transport_options={}, hostname="127.0.0.1", virtual_host=None))) - # create the _connparams with overriden connection_class + # create the _connparams with overridden connection_class connparams = chan._connparams(asynchronous=True) # create redis.Connection redis_connection = connparams['connection_class']()