diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..440f225 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,70 @@ +--- +name: tests + +"on": + push: + pull_request: + +jobs: + +# misc: +# name: "Linting configs and git" +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# fetch-depth: 12 +# +# - uses: docker://docker.io/tamasfe/taplo:latest +# name: "Lint TOMLs" +# with: +# args: fmt --check --diff +# +# - uses: actions/setup-python@v5 +# - name: "Install tox" +# run: | +# pip install tox +# - name: "Lint YAMLs" +# run: | +# tox -e lint-yaml +# - name: "Lint git" +# run: | +# tox -e lint-git + +# lint: +# name: "Linting and type checking" +# runs-on: ubuntu-24.04 +# strategy: +# fail-fast: true +# steps: +# - uses: actions/checkout@v4 +# - uses: actions/setup-python@v5 +# with: +# python-version: "3.13" +# - name: "Install tox" +# run: | +# pip install tox +# - name: "Lint formatting" +# run: | +# tox -e lint-py +# - name: "Type checking" +# run: | +# tox -e lint-mypy + + tests: + name: "Run unit tests" + runs-on: ubuntu-24.04 + strategy: + fail-fast: true + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: "Installing tox" + run: pip install tox + - name: "Executing unit tests" + run: | + tox run -e ${{ matrix.python-version }} diff --git a/src/inject/__init__.py b/src/inject/__init__.py index 02bb2c7..f324873 100644 --- a/src/inject/__init__.py +++ b/src/inject/__init__.py @@ -73,6 +73,8 @@ def my_config(binder): inject.configure(my_config) """ +from __future__ import annotations + import contextlib from inject._version import __version__ @@ -84,7 +86,7 @@ def my_config(binder): from functools import wraps from typing import (Any, Awaitable, Callable, Dict, Generic, Hashable, Optional, Set, Type, TypeVar, Union, cast, get_type_hints, - overload, no_type_check, Self) + overload, no_type_check) _HAS_PEP604_SUPPORT = sys.version_info[:3] >= (3, 10, 0) # PEP 604 if _HAS_PEP604_SUPPORT: @@ -214,8 +216,12 @@ def __init__( else: self._bindings = {} + # NOTE(pyctrl): only since 3.12 + # @overload + # def get_instance(self, cls: Type[T]) -> T: ... + @overload - def get_instance(self, cls: Type[T]) -> T: ... + def get_instance(self, cls: Binding) -> T: ... @overload def get_instance(self, cls: Hashable) -> Injectable: ... @@ -521,11 +527,19 @@ def sign_up(name, email, cache, db): return _ParametersInjection(**args_to_classes) +# NOTE(pyctrl): only since 3.12 +# @overload +# def autoparams[T](fn: Callable[..., T]) -> Callable[..., T]: ... + @overload -def autoparams[T](fn: Callable[..., T]) -> Callable[..., T]: ... +def autoparams(fn: Callable) -> Callable: ... + +# NOTE(pyctrl): only since 3.12 +# @overload +# def autoparams[C: Callable](*selected: str) -> Callable[[C], C]: ... @overload -def autoparams[C: Callable](*selected: str) -> Callable[[C], C]: ... +def autoparams(*selected: str) -> Callable: ... @no_type_check def autoparams(*selected: str):