Skip to content
Open
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 .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
- package-ecosystem: "uv" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
python-version: "3.14"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
run: uv sync --group coverage
- name: Run Tests and Record Coverage
run: |
tox -e coverage
cd unittests
uv run --project .. --group coverage coverage run -m pytest
uv run --project .. --group coverage coverage html --omit .venv/*,unittests/*
uv run --project .. --group coverage coverage report --fail-under 80 --omit .venv/*,unittests/*
12 changes: 5 additions & 7 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ jobs:
tool: ["black", "isort"]
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
python-version: "3.14"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[formatting]
run: uv sync --group formatting
- name: ${{ matrix.tool }} Code Formatter
run: |
${{ matrix.tool }} . --check
uv run --group formatting ${{ matrix.tool }} . --check
17 changes: 7 additions & 10 deletions .github/workflows/packaging_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run Packaging Test
run: |
tox -e test_packaging
python-version: "3.14"
- name: Build package
run: uv build
- name: Check package
run: uv publish --dry-run dist/*
29 changes: 10 additions & 19 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
python-version: "3.14"
- name: Install dependencies
run: uv sync --group tests
- name: Run tests
run: |
tox -e tests
run: uv run --group tests pytest

build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
Expand All @@ -41,18 +38,12 @@ jobs:
needs: tests
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test_packaging]
python-version: "3.14"
- name: Build wheel and source distributions
run: |
python -m build
run: uv build
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1

19 changes: 12 additions & 7 deletions .github/workflows/pythonlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ jobs:
linter-env: ["linting", "type_check"]
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: 3.14
python-version: "3.14"
- name: Install Dependencies
run: uv sync --group ${{ matrix.linter-env }}
- name: Run linting
if: matrix.linter-env == 'linting'
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run ${{ matrix.linter-env }} via Tox
uv run --group linting pylint src/generics
uv run --group linting pylint unittests --rcfile=unittests/.pylintrc
- name: Run type_check
if: matrix.linter-env == 'type_check'
run: |
tox -e ${{ matrix.linter-env }}
uv run --group type_check mypy --show-error-codes src/generics
uv run --group type_check mypy --show-error-codes --enable-incomplete-feature=NewGenericSyntax unittests
19 changes: 9 additions & 10 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ jobs:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: uv sync --group tests
- name: Run the Unit Tests
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run the Unit Tests via Tox
run: |
TOXENV=tests-py${{ matrix.python-version }}
TOXENV=${TOXENV//.}
echo "Running the unit tests via Tox with the environment $TOXENV"
tox -e $TOXENV
if [ "${{ matrix.python-version }}" = "3.10" ] || [ "${{ matrix.python-version }}" = "3.11" ]; then
uv run --group tests pytest --ignore=unittests/test_py_312.py
else
uv run --group tests pytest
fi
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ dmypy.json
# vscode settings
.vscode/

src/_your_package_version.py
src/_generics_version.py
10 changes: 7 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# to update all repo revisions just run: pre-commit autoupdate
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.11.31
hooks:
- id: uv-lock
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 26.5.1
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 8.0.1
hooks:
- id: isort
name: isort (python)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
![Black status badge](https://github.com/Hochfrequenz/python-generics/workflows/Formatting/badge.svg)

Ever wondered how to do something like this?

```python
from typing import Generic, TypeVar

Expand Down Expand Up @@ -109,7 +109,7 @@ assert MySubType().get_type() == str
```

## Limitations
Due to how generics are implemented in Python, it is not possible to
Due to how generics are implemented in Python, it is not possible to
determine the value of a `TypeVar` inside the constructor. This would require
some stack trace analysis and is currently not implemented in this project.
However, for most scenarios there is an easy workaround for this.
Expand All @@ -133,7 +133,7 @@ from generics import get_filled_type
class MySuperType[T]:
def __init__(self):
self._my_type: type[T] | None = None

@property
def my_type(self) -> type[T]:
if self._my_type is None:
Expand Down
68 changes: 41 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,9 @@ classifiers = [
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
dependencies = [] # add all the dependencies from requirements.in here, too
dependencies = []
dynamic = ["readme", "version"]

[project.optional-dependencies]
coverage = [
"coverage==7.15.2"
]
formatting = [
"black==26.5.1",
"isort==8.0.1"
]
linting = [
"pylint==4.0.6"
]
spellcheck = [
"codespell==2.4.3"
]
test_packaging = [
"build==1.5.1",
"twine==6.2.0"
]
tests = [
"pydantic==2.13.4",
"pytest==9.1.1"
]
type_check = [
"mypy==2.3.0"
]

[project.urls]
Changelog = "https://github.com/Hochfrequenz/python-generics/releases"
Homepage = "https://github.com/Hochfrequenz/python-generics"
Expand All @@ -64,6 +38,46 @@ profile = "black"
max-line-length = 120
disable = "fixme,too-few-public-methods"

[tool.codespell]
skip = "uv.lock"

[dependency-groups]
tests = [
"pydantic==2.13.4",
"pytest==9.1.1"
]
coverage = [
"coverage==7.15.2",
{include-group = "tests"}
]
linting = [
"pylint==4.0.6",
{include-group = "tests"}
]
type_check = [
"mypy==2.3.0",
{include-group = "tests"}
]
spellcheck = [
"codespell==2.4.3"
]
formatting = [
"black==26.5.1",
"isort==8.0.1"
]
dev = [
{include-group = "tests"},
{include-group = "coverage"},
{include-group = "linting"},
{include-group = "type_check"},
{include-group = "spellcheck"},
{include-group = "formatting"},
"pre-commit"
]

[tool.uv]
default-groups = []

[build-system]
requires = ["hatchling>=1.8.0", "hatch-vcs", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"
Expand Down
Empty file removed requirements.in
Empty file.
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

Loading
Loading