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
15 changes: 15 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ jobs:
# run: |
# tox -e lint-mypy

types:
name: "Type checking (public API)"
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.14"
- name: "Install tox"
run: |
pip install tox
- name: "Type checking (public API)"
run: |
tox -e lint-types

tests:
name: "Run unit tests"
runs-on: ubuntu-24.04
Expand Down
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defineConstant = { DEBUG = true }
exclude = []
executionEnvironments = []
ignore = []
include = ["src/inject", "tests"]
include = ["src/inject", "tests", "typing_checks"]
pythonPlatform = "Linux"
pythonVersion = "3.11"
reportMissingImports = true
Expand Down Expand Up @@ -275,6 +275,7 @@ env_list = [
"fmt-py",
"fmt-toml",
"lint-py",
"lint-types",
#"lint-mypy", # TODO(pyctrl): make it green & uncomment
"lint-toml",
"lint-yaml",
Expand All @@ -289,6 +290,7 @@ fmt = [
]
lint = [
"lint-py",
"lint-types",
#"lint-mypy", # TODO(pyctrl): make it green & uncomment
"lint-toml",
"lint-yaml",
Expand Down Expand Up @@ -325,6 +327,18 @@ commands = [
],
]

[tool.tox.env.lint-types]
description = "Type-check the public-API typing guards"
deps = ["mypy"]
commands = [
[
"mypy",
{ replace = "posargs", default = [
"typing_checks",
], extend = true },
],
]

[tool.tox.env.lint-mypy]
description = "Type checking"
deps = ["mypy"]
Expand Down
4 changes: 2 additions & 2 deletions src/inject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ def attr() -> Injectable: ...


@t.overload
def attr(cls: t.Hashable) -> Injectable: ...
def attr(cls: type[T]) -> T: ...


@t.overload
def attr(cls: type[T]) -> T: ...
def attr(cls: t.Hashable) -> Injectable: ...


def attr(cls=_MISSING):
Expand Down
Empty file added typing_checks/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions typing_checks/attr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Static-typing regression guard for ``inject.attr``."""

from typing_extensions import assert_type

import inject


class _Service:
pass


class _Repository:
pass


assert_type(inject.attr(_Service), _Service)
assert_type(inject.attr(_Repository), _Repository)
Loading