Skip to content

Commit 11d3662

Browse files
committed
PEP 561 py.typed marker
1 parent 45e45c6 commit 11d3662

File tree

7 files changed

+60
-13
lines changed

7 files changed

+60
-13
lines changed

.github/workflows/tests.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
code-quality:
14-
name: Code Quality
14+
name: Code quality
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
@@ -29,6 +29,9 @@ jobs:
2929
run: |
3030
ruff format --check
3131
ruff check
32+
33+
- name: Type check
34+
run: |
3235
mypy --install-types --non-interactive
3336
3437
tests:
@@ -64,11 +67,28 @@ jobs:
6467
token: ${{ secrets.CODECOV_TOKEN }}
6568
if: ${{ matrix.os == 'ubuntu-latest' }}
6669

70+
test-build-and-install:
71+
name: "Test build and install"
72+
needs: code-quality
73+
runs-on: ubuntu-latest
74+
75+
steps:
76+
- uses: actions/checkout@v4
77+
78+
- name: Set up Python and uv
79+
uses: drivendataorg/setup-python-uv-action@v1
80+
with:
81+
python-version: "3.12"
82+
83+
- name: Install build
84+
run: |
85+
uv pip install build
86+
6787
- name: Build distribution and test installation
6888
shell: bash
6989
run: |
7090
python -m build
71-
if [[ ${{ matrix.os }} == "windows-latest" ]]; then
91+
if [[ ${{ runner.os }} == "Windows" ]]; then
7292
PYTHON_BIN=Scripts/python
7393
else
7494
PYTHON_BIN=bin/python

example.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Tuple
1+
from typing import Tuple
22

33
from pydantic import BaseModel
44

@@ -12,7 +12,7 @@ class MyModel(BaseModel):
1212

1313

1414
m = MyModel(
15-
sorted_dict={"charlie": 2, "alpha": 3, "bravo": 1},
15+
sorted_dict={"carol": 2, "alice": 3, "bob": 1},
1616
sorted_list=[3.0, 2.0, 1.0],
1717
sorted_set={(2, 9), (3, 5), (1, 3)},
1818
)
@@ -25,8 +25,3 @@ class MyModel(BaseModel):
2525
assert m == m2
2626
print(repr(m2))
2727
#> MyModel(sorted_dict=SortedDict({'alpha': 3, 'bravo': 1, 'charlie': 2}), sorted_list=SortedList([1.0, 2.0, 3.0]), sorted_set=SortedSet([(1, 3), (2, 9), (3, 5)]))
28-
29-
if TYPE_CHECKING:
30-
reveal_type(m.sorted_dict) # noqa: F821
31-
reveal_type(m.sorted_list) # noqa: F821
32-
reveal_type(m.sorted_set) # noqa: F821

pyproject.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tests = ["pytest>=6"]
3333
"Bug Tracker" = "https://github.com/jayqi/sortedcontainers-pydantic/issues"
3434

3535
[tool.hatch.version]
36-
path = "sortedcontainers_pydantic.py"
36+
path = "sortedcontainers_pydantic/__init__.py"
3737

3838
## TOOLS ##
3939

@@ -54,11 +54,10 @@ known-first-party = ["sortedcontainers_pydantic"]
5454
force-sort-within-sections = true
5555

5656
[tool.mypy]
57-
files = ["sortedcontainers_pydantic.py", "example.py"]
58-
ignore_missing_imports = true
57+
files = ["sortedcontainers_pydantic", "tests/typechecks.py", "example.py"]
5958
plugins = ["pydantic.mypy"]
6059

6160
[tool.pytest.ini_options]
6261
minversion = "6.0"
6362
addopts = "--cov=sortedcontainers_pydantic --cov-report=term --cov-report=html --cov-report=xml -v"
64-
testpaths = ["tests.py"]
63+
testpaths = ["tests"]
File renamed without changes.

sortedcontainers_pydantic/py.typed

Whitespace-only changes.
File renamed without changes.

tests/typechecks.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import TYPE_CHECKING
2+
3+
from pydantic import BaseModel
4+
5+
from sortedcontainers_pydantic import SortedDict, SortedList, SortedSet
6+
7+
8+
class MyModel(BaseModel):
9+
dct: SortedDict[str, int] = SortedDict()
10+
lst: SortedList[int] = SortedList()
11+
st: SortedSet[int] = SortedSet()
12+
13+
14+
if TYPE_CHECKING:
15+
m = MyModel()
16+
17+
reveal_type(m.dct) # noqa: F821
18+
reveal_type(m.lst) # noqa: F821
19+
reveal_type(m.st) # noqa: F821
20+
21+
MyModel(dct={"c": 1, "a": 2, "b": 3})
22+
MyModel(dct=[("c", 1), ("a", 2), ("b", 3)])
23+
MyModel(dct=(pair for pair in [("c", 1), ("a", 2), ("b", 3)]))
24+
25+
MyModel(lst=[3, 1, 2])
26+
MyModel(lst=(3, 1, 2))
27+
MyModel(lst={3, 1, 2})
28+
MyModel(lst=(i for i in [3, 1, 2]))
29+
30+
MyModel(st=[3, 1, 2])
31+
MyModel(st=(3, 1, 2))
32+
MyModel(st={3, 1, 2})
33+
MyModel(st=(i for i in [3, 1, 2]))

0 commit comments

Comments
 (0)