Skip to content

Commit a6a0cb8

Browse files
authored
Make the library strictly typed (#328)
1 parent 895d6a8 commit a6a0cb8

6 files changed

Lines changed: 29 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ jobs:
132132
pre-commit run --hook-stage manual ruff-format --all-files --show-diff-on-failure
133133
env:
134134
RUFF_OUTPUT_FORMAT: github
135-
# - name: Run mypy
136-
# run: mypy pyesef
135+
- name: Run mypy
136+
run: |
137+
source .venv/bin/activate
138+
pre-commit run --hook-stage manual mypy --all-files --show-diff-on-failure
137139
138140
pytest:
139141
name: Run test suite

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ repos:
2020
- id: no-commit-to-branch
2121
args:
2222
- --branch=main
23+
- repo: local
24+
hooks:
25+
- id: mypy
26+
name: mypy
27+
entry: >
28+
./script/run-in-env.sh mypy --config-file pyproject.toml
29+
language: script
30+
types: [python]
31+
require_serial: true
32+
files: ^pygleif/.+\.py$

pygleif/api/data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ class Links(BaseSchema):
127127
class Relationships(BaseSchema):
128128
"""Represent a relationships ."""
129129

130-
managing_lou: Links = None
131-
lei_issuer: Links = None
132-
field_modifications: Links = None
133-
direct_parent: Links = None
134-
ultimate_parent: Links = None
130+
managing_lou: Links | None = None
131+
lei_issuer: Links | None = None
132+
field_modifications: Links | None = None
133+
direct_parent: Links | None = None
134+
ultimate_parent: Links | None = None
135135

136136

137137
class Data(BaseSchema):

pygleif/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class PyGleifBase(ABC):
2929
search_string: str
3030

3131
@property
32-
def json_response(self) -> list[Any] | dict[Any, Any]:
32+
def json_response(self) -> dict[Any, Any]:
3333
"""Return JSON response."""
3434
full_url = f"{self.BASE_URL}{self.search_string}"
3535
try:
3636
with request.urlopen(
3737
full_url,
3838
timeout=self.TIMEOUT_SECOND,
3939
) as fdesc:
40-
return cast(dict[Any, Any] | list[Any], json.loads(fdesc.read()))
40+
return cast(dict[Any, Any], json.loads(fdesc.read()))
4141
except error.HTTPError as e:
4242
if e.code == HttpErrorCodes.NOT_FOUND:
4343
raise PyGLEIFApiError(f"Resource {full_url} not found")

pygleif/py.typed

Whitespace-only changes.

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ version = {file = "pygleif/VERSION"}
4949
[tool.setuptools.packages.find]
5050
exclude = ["tests", "tests*"]
5151

52+
[tool.setuptools.package-data]
53+
"pygleif" = ["py.typed"]
54+
5255
[tool.pytest.ini_options]
5356
testpaths = [
5457
"tests",
@@ -120,3 +123,8 @@ known-first-party = [
120123
"pygleif",
121124
"tests",
122125
]
126+
127+
[tool.mypy]
128+
python_version = "3.11"
129+
strict = true
130+
plugins = "pydantic.mypy"

0 commit comments

Comments
 (0)