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
70 changes: 70 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
22 changes: 18 additions & 4 deletions src/inject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def my_config(binder):
inject.configure(my_config)

"""
from __future__ import annotations

import contextlib

from inject._version import __version__
Expand All @@ -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:
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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):
Expand Down