Skip to content

Commit

Permalink
Bump pyupgrade version and add __future__.annotations import
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored and auvipy committed Apr 15, 2022
1 parent a93099b commit 7516daf
Show file tree
Hide file tree
Showing 160 changed files with 416 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v2.32.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]
args: ["--py37-plus"]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
Expand Down
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from sphinx_celery import conf

globals().update(conf.build_config(
Expand Down
2 changes: 2 additions & 0 deletions examples/complete_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

from __future__ import annotations

from pprint import pformat

from kombu import Connection, Consumer, Exchange, Queue, eventloop
Expand Down
2 changes: 2 additions & 0 deletions examples/complete_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

from __future__ import annotations

from kombu import Connection, Exchange, Producer, Queue

#: By default messages sent to exchanges are persistent (delivery_mode=2),
Expand Down
2 changes: 2 additions & 0 deletions examples/experimental/async_consume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import annotations

from kombu import Connection, Consumer, Exchange, Producer, Queue
from kombu.asynchronous import Hub

Expand Down
2 changes: 2 additions & 0 deletions examples/hello_consumer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from kombu import Connection

with Connection('amqp://guest:guest@localhost:5672//') as conn:
Expand Down
2 changes: 2 additions & 0 deletions examples/hello_publisher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime

from kombu import Connection
Expand Down
2 changes: 2 additions & 0 deletions examples/memory_transport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Example that use memory transport for message produce.
"""
from __future__ import annotations

import time

from kombu import Connection, Consumer, Exchange, Queue
Expand Down
2 changes: 2 additions & 0 deletions examples/rpc-tut6/rpc_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import annotations

from kombu import Connection, Consumer, Producer, Queue, uuid


Expand Down
2 changes: 2 additions & 0 deletions examples/rpc-tut6/rpc_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import annotations

from kombu import Connection, Queue
from kombu.mixins import ConsumerProducerMixin

Expand Down
2 changes: 2 additions & 0 deletions examples/simple_eventlet_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from __future__ import annotations

import eventlet

from kombu import Connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_eventlet_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from __future__ import annotations

import eventlet

from kombu import Connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""

from __future__ import annotations

from kombu import Connection

#: Create connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from __future__ import annotations

from kombu import Connection

#: Create connection
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_task_queue/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from kombu.pools import producers

from .queues import task_exchange
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_task_queue/queues.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from kombu import Exchange, Queue

task_exchange = Exchange('tasks', type='direct')
Expand Down
3 changes: 3 additions & 0 deletions examples/simple_task_queue/tasks.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import annotations


def hello_task(who='world'):
print(f'Hello {who}')
2 changes: 2 additions & 0 deletions examples/simple_task_queue/worker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from kombu.log import get_logger
from kombu.mixins import ConsumerMixin
from kombu.utils.functional import reprcall
Expand Down
6 changes: 4 additions & 2 deletions kombu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Messaging library for Python."""

from __future__ import annotations

import os
import re
import sys
from collections import namedtuple
from typing import Any, List, cast
from typing import Any, cast

__version__ = '5.2.4'
__author__ = 'Ask Solem'
Expand Down Expand Up @@ -78,7 +80,7 @@ def __getattr__(self, name: str) -> Any:
return getattr(module, name)
return ModuleType.__getattribute__(self, name)

def __dir__(self) -> List[str]:
def __dir__(self) -> list[str]:
result = list(new_module.__all__)
result.extend(('__file__', '__path__', '__doc__', '__all__',
'__docformat__', '__name__', '__path__', 'VERSION',
Expand Down
2 changes: 2 additions & 0 deletions kombu/abstract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Object utilities."""

from __future__ import annotations

from copy import copy

from .connection import maybe_channel
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Event loop."""

from __future__ import annotations

from kombu.utils.eventio import ERR, READ, WRITE

from .hub import Hub, get_event_loop, set_event_loop
Expand Down
8 changes: 5 additions & 3 deletions kombu/asynchronous/aws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Any, Optional
from __future__ import annotations

from typing import Any

from kombu.asynchronous.aws.sqs.connection import AsyncSQSConnection


def connect_sqs(
aws_access_key_id: Optional[str] = None,
aws_secret_access_key: Optional[str] = None,
aws_access_key_id: str | None = None,
aws_secret_access_key: str | None = None,
**kwargs: Any
) -> AsyncSQSConnection:
"""Return async connection to Amazon SQS."""
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Amazon AWS Connection."""

from __future__ import annotations

from email import message_from_bytes
from email.mime.message import MIMEMessage

Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/ext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Amazon boto3 interface."""

from __future__ import annotations

try:
import boto3
from botocore import exceptions
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/sqs/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Amazon SQS Connection."""

from __future__ import annotations

from vine import transform

from kombu.asynchronous.aws.connection import AsyncAWSQueryConnection
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/sqs/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Amazon SQS boto3 interface."""


from __future__ import annotations

try:
import boto3
except ImportError:
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/sqs/message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Amazon SQS message implementation."""

from __future__ import annotations

import base64

from kombu.message import Message
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/aws/sqs/queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Amazon SQS queue implementation."""

from __future__ import annotations

from vine import transform

from .message import AsyncMessage
Expand Down
2 changes: 2 additions & 0 deletions kombu/asynchronous/debug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Event-loop debugging tools."""

from __future__ import annotations

from kombu.utils.eventio import ERR, READ, WRITE
from kombu.utils.functional import reprcall

Expand Down
8 changes: 5 additions & 3 deletions kombu/asynchronous/http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import TYPE_CHECKING, Optional
from __future__ import annotations

from typing import TYPE_CHECKING

from kombu.asynchronous import get_event_loop
from kombu.asynchronous.http.base import Headers, Request, Response
Expand All @@ -10,13 +12,13 @@
__all__ = ('Client', 'Headers', 'Response', 'Request')


def Client(hub: Optional[Hub] = None, **kwargs: int) -> "CurlClient":
def Client(hub: Hub | None = None, **kwargs: int) -> CurlClient:
"""Create new HTTP client."""
from .curl import CurlClient
return CurlClient(hub, **kwargs)


def get_client(hub: Optional[Hub] = None, **kwargs: int) -> "CurlClient":
def get_client(hub: Hub | None = None, **kwargs: int) -> CurlClient:
"""Get or create HTTP client bound to the current event loop."""
hub = hub or get_event_loop()
try:
Expand Down
10 changes: 6 additions & 4 deletions kombu/asynchronous/http/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Base async HTTP client implementation."""

from __future__ import annotations

import sys
from http.client import responses
from typing import TYPE_CHECKING, Optional, Type
from typing import TYPE_CHECKING

from vine import Thenable, maybe_promise, promise

Expand Down Expand Up @@ -259,8 +261,8 @@ def __enter__(self):

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional['TracebackType']
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None
) -> None:
self.close()
5 changes: 3 additions & 2 deletions kombu/asynchronous/http/curl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""HTTP Client using pyCurl."""

from __future__ import annotations

from collections import deque
from functools import partial
from io import BytesIO
from time import time
from typing import Optional

from kombu.asynchronous.hub import READ, WRITE, Hub, get_event_loop
from kombu.exceptions import HttpError
Expand Down Expand Up @@ -37,7 +38,7 @@ class CurlClient(BaseClient):

Curl = Curl

def __init__(self, hub: Optional[Hub] = None, max_clients: int = 10):
def __init__(self, hub: Hub | None = None, max_clients: int = 10):
if pycurl is None:
raise ImportError('The curl client requires the pycurl library.')
hub = hub or get_event_loop()
Expand Down
9 changes: 5 additions & 4 deletions kombu/asynchronous/hub.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Event loop implementation."""

from __future__ import annotations

import errno
import threading
from contextlib import contextmanager
from queue import Empty
from time import sleep
from types import GeneratorType as generator
from typing import Optional

from vine import Thenable, promise

Expand All @@ -20,7 +21,7 @@
__all__ = ('Hub', 'get_event_loop', 'set_event_loop')
logger = get_logger(__name__)

_current_loop: Optional["Hub"] = None
_current_loop: Hub | None = None

W_UNKNOWN_EVENT = """\
Received unknown event %r for fd %r, please contact support!\
Expand All @@ -40,12 +41,12 @@ def _dummy_context(*args, **kwargs):
yield


def get_event_loop() -> Optional["Hub"]:
def get_event_loop() -> Hub | None:
"""Get current event loop object."""
return _current_loop


def set_event_loop(loop: Optional["Hub"]) -> Optional["Hub"]:
def set_event_loop(loop: Hub | None) -> Hub | None:
"""Set the current event loop object."""
global _current_loop
_current_loop = loop
Expand Down
Loading

0 comments on commit 7516daf

Please sign in to comment.