Skip to content

Commit

Permalink
Take advantage of having dropped Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Darsstar committed Mar 4, 2024
1 parent 28d970d commit 709ecc8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 52 deletions.
8 changes: 2 additions & 6 deletions aio_pika/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
from .robust_queue import RobustQueue


try:
from importlib.metadata import Distribution
__version__ = Distribution.from_name("aio-pika").version
except ImportError:
import pkg_resources
__version__ = pkg_resources.get_distribution("aio-pika").version
from importlib.metadata import Distribution
__version__ = Distribution.from_name("aio-pika").version


__all__ = (
Expand Down
11 changes: 2 additions & 9 deletions aio_pika/abc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import dataclasses
import sys
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import datetime, timedelta
Expand All @@ -9,16 +8,10 @@
from types import TracebackType
from typing import (
Any, AsyncContextManager, AsyncIterable, Awaitable, Callable, Dict,
Generator, Iterator, Mapping, Optional, Tuple, Type, TypeVar, Union,
overload,
Generator, Iterator, Literal, Mapping, Optional, Tuple, Type, TypedDict,
TypeVar, Union, overload,
)


if sys.version_info >= (3, 8):
from typing import Literal, TypedDict
else:
from typing_extensions import Literal, TypedDict

import aiormq.abc
from aiormq.abc import ExceptionType
from pamqp.common import Arguments, FieldValue
Expand Down
11 changes: 3 additions & 8 deletions aio_pika/queue.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
import sys
from functools import partial
from types import TracebackType
from typing import Any, Awaitable, Callable, Optional, Set, Type, overload
from typing import (
Any, Awaitable, Callable, Literal, Optional, Set, Type, overload,
)

import aiormq
from aiormq.abc import DeliveredMessage
Expand All @@ -19,12 +20,6 @@
from .tools import CallbackCollection, create_task, ensure_awaitable


if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


log = get_logger(__name__)


Expand Down
29 changes: 8 additions & 21 deletions aio_pika/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,12 @@

def iscoroutinepartial(fn: Callable[..., Any]) -> bool:
"""
Function returns True if function is a partial instance of coroutine.
See additional information here_.
:param fn: Function
:return: bool
.. _here: https://goo.gl/C0S4sQ
Use Python 3.8's inspect.iscoroutinefunction() instead
"""

while True:
parent = fn

fn = getattr(parent, "func", None) # type: ignore

if fn is None:
break

return asyncio.iscoroutinefunction(parent)
warnings.warn(
"Use inspect.iscoroutinefunction() instead.", DeprecationWarning
)
return asyncio.iscoroutinefunction(fn)


def _task_done(future: asyncio.Future) -> None:
Expand All @@ -57,8 +44,8 @@ def create_task(
) -> Awaitable[T]:
loop = loop or asyncio.get_event_loop()

if iscoroutinepartial(func):
task = loop.create_task(func(*args, **kwargs)) # type: ignore
if inspect.iscoroutinefunction(func):
task = loop.create_task(func(*args, **kwargs))
task.add_done_callback(_task_done)
return task

Expand Down Expand Up @@ -260,7 +247,7 @@ def ensure_awaitable(
if inspect.iscoroutinefunction(func):
return func

if inspect.isfunction(func) and not iscoroutinepartial(func):
if inspect.isfunction(func):
warnings.warn(
f"You probably registering the non-coroutine function {func!r}. "
"This is deprecated and will be removed in future releases. "
Expand Down
8 changes: 2 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@


# noinspection PyUnresolvedReferences
try:
from importlib.metadata import Distribution
__version__ = Distribution.from_name("aio-pika").version
except ImportError:
import pkg_resources
__version__ = pkg_resources.get_distribution("aio-pika").version
from importlib.metadata import Distribution
__version__ = Distribution.from_name("aio-pika").version

sys.path.insert(0, os.path.abspath(os.path.dirname("__file__")))

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ packages = [{ include = "aio_pika" }]
python = "^3.8"
aiormq = "~6.8.0"
yarl = [{ version = '*'}]
typing_extensions = [{ version = '*', python = "< 3.8" }]
# for pkg_resources
setuptools = [{ version = '*', python = "< 3.8" }]

Expand Down

0 comments on commit 709ecc8

Please sign in to comment.