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: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: remimd
buy_me_a_coffee: remimd
15 changes: 15 additions & 0 deletions .github/actions/code-style/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Code Style
description: Check code style

runs:
using: "composite"
steps:
- name: Ruff
shell: bash
run: |
uv run ruff format --check
uv run ruff check

- name: MyPy
shell: bash
run: uv run mypy ./
16 changes: 16 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deploy
description: Publish package on PyPI
inputs:
version:
description: "Package version."
required: true

runs:
using: "composite"
steps:
- name: Publish
shell: bash
run: |
uv version ${{ inputs.version }}
uv build
uv publish
19 changes: 19 additions & 0 deletions .github/actions/environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Environment
description: Set up the environment
inputs:
python-version:
description: "Python version."
required: false
default: "3.12"

runs:
using: "composite"
steps:
- name: Install UV
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ inputs.python-version }}

- name: Install Dependencies
shell: bash
run: uv sync
9 changes: 9 additions & 0 deletions .github/actions/tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Tests
description: Run all tests

runs:
using: "composite"
steps:
- name: Pytest
shell: bash
run: uv run pytest
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

updates:
- package-ecosystem: "uv"
directory: "/"
target-branch: "dev"
schedule:
interval: "weekly"
groups:
safe:
patterns:
- "*"
update-types:
- "minor"
- "patch"
major:
patterns:
- "*"
update-types:
- "major"
26 changes: 26 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CD

on:
release:
types: [published]

jobs:
cd:
name: Continuous Delivery
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Run checkout
uses: actions/checkout@v5

- name: Set up environment
uses: ./.github/actions/environment

- name: Deploy
uses: ./.github/actions/deploy
with:
version: ${{ github.event.release.tag_name }}
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches:
- dev
- prod
pull_request:

jobs:
ci:
strategy:
matrix:
python-version: ["3.12", "3.13", "3.14"]

name: Continuous Integration ・ Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Run checkout
uses: actions/checkout@v5

- name: Set up environment
uses: ./.github/actions/environment
with:
python-version: ${{ matrix.python-version }}

- name: Check code style
uses: ./.github/actions/code-style

- name: Tests
uses: ./.github/actions/tests
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 remimd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
before_commit: lint mypy pytest

install:
uv sync

update:
uv lock --upgrade
uv sync

lint:
uv run ruff format
uv run ruff check --fix

mypy:
uv run mypy ./

pytest:
uv run pytest
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# type-analyzer

[![CI](https://github.com/100nm/type-analyzer/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/type-analyzer)
[![PyPI - Version](https://img.shields.io/pypi/v/type-analyzer.svg?color=blue)](https://pypi.org/project/type-analyzer)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/type-analyzer.svg?color=blue)](https://pypistats.org/packages/type-analyzer)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

## Quick start

### matching_types

```python
from type_analyzer import MatchingTypesConfig, matching_types

# ----- Union type -----

matching_types(str | int)
# => (str, int)

# ----- Generic type alias -----

type StringOr[T] = str | T

config = MatchingTypesConfig(with_type_alias_value=True)
matching_types(StringOr[int], config)
# => (StringOr[int], str, int)

# ----- Generic classes -----

class A[T]:
...

class B[T]:
...

class C[T1, T2](A[T1], B[T2]):
...

config = MatchingTypesConfig(with_mro=True)
matching_types(C[str, int], config)
# => (C[str, int], A[str], B[int])
```
82 changes: 82 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[project]
name = "type-analyzer"
version = "0.0.0"
description = "Functions for introspecting Python type hints."
license = "MIT"
license-files = ["LICENSE"]
readme = "README.md"
requires-python = ">=3.12, <3.15"
authors = [{ name = "remimd" }]
keywords = []
classifiers = [
"Development Status :: 4 - Beta",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Natural Language :: English",
"Typing :: Typed",
]
dependencies = []

[dependency-groups]
dev = [
"hatch",
"mypy",
"ruff",
]
test = [
"pytest",
"pytest-cov",
]

[project.urls]
Repository = "https://github.com/100nm/type-analyzer"

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

[tool.coverage.report]
exclude_also = ["raise NotImplementedError"]

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.pytest]
python_files = ["test_*.py"]
addopts = ["--tb", "short", "--cov", "./", "--cov-report", "term-missing:skip-covered"]
testpaths = ["./tests/"]
tmp_path_retention_count = "1"
tmp_path_retention_policy = "failed"

[tool.ruff]
line-length = 88
indent-width = 4

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.ruff.lint]
extend-select = ["I", "N"]
fixable = ["ALL"]

[tool.uv]
default-groups = ["dev", "test"]
package = false
Empty file added tests/__init__.py
Empty file.
Empty file added tests/core/__init__.py
Empty file.
Loading