Skip to content

Commit

Permalink
Fix Ruff / mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-git committed Mar 27, 2024
1 parent f798237 commit 7fe09ec
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/magic_di/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import functools
import inspect
from collections.abc import Iterable
from dataclasses import dataclass
from threading import Lock
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast

if TYPE_CHECKING:
from collections.abc import Iterable

from magic_di import ConnectableProtocol

T = TypeVar("T")
Expand Down
3 changes: 2 additions & 1 deletion src/magic_di/_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import inspect
import logging
from collections.abc import Callable, Iterable, Iterator
from contextlib import contextmanager
from threading import Lock
from typing import (
Expand All @@ -25,6 +24,8 @@
from magic_di.exceptions import InjectionError, InspectionError

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Iterator

from magic_di._connectable import ConnectableProtocol

# flag to use in typing.Annotated
Expand Down
8 changes: 4 additions & 4 deletions src/magic_di/_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import Any, TypeVar, Union, cast, get_args
from typing import Any, TypeVar, cast, get_args
from typing import get_type_hints as _get_type_hints

from magic_di import ConnectableProtocol

LegacyUnionType = type(Union[object, None])
LegacyUnionType = type(object | None)

try:
from types import UnionType # type: ignore[import-error,unused-ignore]
except ImportError:
UnionType = LegacyUnionType # type: ignore[misc, assignment]
UnionType = LegacyUnionType # type: ignore[misc]


T = TypeVar("T")
Expand Down Expand Up @@ -40,7 +40,7 @@ def get_cls_from_optional(cls: T) -> T:
Returns:
T: Extracted class
"""
if not isinstance(cls, (UnionType, LegacyUnionType)):
if not isinstance(cls, UnionType | LegacyUnionType):
return cls

args = get_args(cls)
Expand Down
6 changes: 4 additions & 2 deletions src/magic_di/celery/_async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import asyncio
import threading
from collections.abc import Coroutine
from dataclasses import dataclass
from typing import Any, TypeVar
from typing import TYPE_CHECKING, Any, TypeVar

if TYPE_CHECKING:
from collections.abc import Coroutine

R = TypeVar("R")

Expand Down
3 changes: 2 additions & 1 deletion src/magic_di/celery/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import os
import threading
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable

from celery import signals
Expand All @@ -13,6 +12,8 @@
from magic_di.celery._async_utils import EventLoop, EventLoopGetter, run_in_event_loop

if TYPE_CHECKING:
from collections.abc import Callable

from celery.loaders.base import BaseLoader


Expand Down
6 changes: 4 additions & 2 deletions src/magic_di/celery/_task.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from __future__ import annotations

import inspect
from collections.abc import Callable
from functools import wraps
from typing import Any, cast, get_type_hints
from typing import TYPE_CHECKING, Any, cast, get_type_hints

from celery.app.task import Task

from magic_di import Connectable, DependencyInjector
from magic_di.celery._async_utils import EventLoop, run_in_event_loop
from magic_di.celery._loader import InjectedCeleryLoaderProtocol

if TYPE_CHECKING:
from collections.abc import Callable


class BaseCeleryConnectableDeps(Connectable): ...

Expand Down
3 changes: 2 additions & 1 deletion src/magic_di/fastapi/_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import inspect
from collections.abc import AsyncIterator, Callable, Iterator
from contextlib import asynccontextmanager
from typing import (
TYPE_CHECKING,
Expand All @@ -17,6 +16,8 @@
from magic_di._injector import DependencyInjector

if TYPE_CHECKING:
from collections.abc import AsyncIterator, Callable, Iterator

from fastapi import FastAPI, routing


Expand Down
3 changes: 1 addition & 2 deletions src/magic_di/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import asyncio
import inspect
from collections.abc import Awaitable
from typing import TYPE_CHECKING, TypeVar, overload

from magic_di import DependencyInjector

if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Awaitable, Callable


T = TypeVar("T")
Expand Down

0 comments on commit 7fe09ec

Please sign in to comment.