Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ repos:
language: system
files: ^minject/.*
- repo: https://github.com/duolingo/pre-commit-hooks.git
rev: 1.8.0
rev: 1.15.0
hooks:
- id: duolingo
4 changes: 2 additions & 2 deletions minject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def __init__(self, api, path): ...
from .registry import Registry, initialize

__all__ = [
"Registry",
"define",
"field",
"inject",
"initialize",
"Registry",
"inject",
]
8 changes: 4 additions & 4 deletions minject/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,14 @@ async def aresolve(self, registry_impl: Resolver) -> Resolver:
# compatability to a legacy system
__all__ = [
"_get_meta",
"async_context",
"bind",
"close_method", # deprecated
"config",
"nested_config",
"define",
"function",
"nested_config",
"reference",
"self_tag",
"start_method", # deprecated
"close_method", # deprecated
"async_context",
"start_method", # deprecated
]
4 changes: 2 additions & 2 deletions minject/inject_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(

def _get_compatible_attrs_define_kwargs() -> Dict[str, bool]:
"""
get kwargs compatible with current running version of attrs
Get kwargs compatible with current running version of attrs
"""
from importlib.metadata import version as importlib_version

Expand All @@ -78,7 +78,7 @@ def _get_compatible_attrs_define_kwargs() -> Dict[str, bool]:

@dataclass(frozen=True)
class _BindingKey:
__slots__ = ("filename", "class_lineno")
__slots__ = ("class_lineno", "filename")
filename: str
class_lineno: int # The line containing the "class" keyword.

Expand Down
2 changes: 1 addition & 1 deletion minject/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _init_object(self, obj: T_co, registry_impl: "Registry") -> None: # type: i

async def _ainit_object(self, obj: T_co, registry_impl: "Registry") -> None: # type: ignore[misc]
"""
asynchronous version of _init_object. Calls _aresolve instead
Asynchronous version of _init_object. Calls _aresolve instead
of _resolve.
"""
init_kwargs = {}
Expand Down
20 changes: 16 additions & 4 deletions minject/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
from contextlib import AsyncExitStack
from textwrap import dedent
from threading import RLock
from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, TypeVar, Union, cast
from typing import (
Any,
Callable,
Dict,
Generic,
Iterable,
List,
Mapping,
Optional,
TypeVar,
Union,
cast,
)

from typing_extensions import Concatenate, ParamSpec

Expand Down Expand Up @@ -258,7 +270,7 @@ def _register_by_metadata(self, meta: RegistryMetadata[T]) -> _RegistryWrapper[T

async def _aregister_by_metadata(self, meta: RegistryMetadata[T]) -> _RegistryWrapper[T]:
"""
async version of _register_by_metadata. Calls _ainit_object instead of _init_object.
Async version of _register_by_metadata. Calls _ainit_object instead of _init_object.
"""
LOG.debug("registering %s", meta)

Expand Down Expand Up @@ -315,7 +327,7 @@ def _get_by_metadata(

async def _aget_by_metadata(self, meta: RegistryMetadata[T]) -> Optional[_RegistryWrapper[T]]:
"""
async version of _get_by_metadata. The default argument has been removed
Async version of _get_by_metadata. The default argument has been removed
from the signature, as there is no use case for it at the time of writing.
Please make a feature request if you need this functionality.
"""
Expand All @@ -328,7 +340,7 @@ async def _aget_by_metadata(self, meta: RegistryMetadata[T]) -> Optional[_Regist
def __len__(self) -> int:
return len(self._objects)

def __contains__(self, key : object) -> bool:
def __contains__(self, key: object) -> bool:
"""Check if an object is contained in the registry.
Note that this method returns True if the object has already been
registered. It is possible that the key provides enough information
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ requires-python = ">=3.9"
dependencies = ["attrs>=17.4", "packaging", "typing_extensions>=4.1"]

[build-system]
requires = ["hatchling>=1.26.1"]
build-backend = "hatchling.build"
requires = ["hatchling>=1.26.1"]

[tool.hatch.version]
path = "minject/__init__.py"
Expand Down
8 changes: 2 additions & 6 deletions tests/test_start_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ def close_func(obj: TestClass) -> None:
def test_start_method_decorator_duplicate(self) -> None:
"""Test that start_method decorator correctly sets up a start function."""

def start_func(obj : "TestClass") -> None:
...
def start_func(obj: "TestClass") -> None: ...

def close_func(obj : "TestClass") -> None:
...
def close_func(obj: "TestClass") -> None: ...

@inject.bind(_start=start_func, _close=close_func)
class TestClass:
Expand All @@ -127,5 +125,3 @@ def noop(self) -> None:

with self.assertRaises(ValueError):
close_method(TestClass, lambda x: x.noop())


Loading