Skip to content

Commit

Permalink
Make the library strictly typed (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggravlingen authored Jul 7, 2024
1 parent 895d6a8 commit a6a0cb8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ jobs:
pre-commit run --hook-stage manual ruff-format --all-files --show-diff-on-failure
env:
RUFF_OUTPUT_FORMAT: github
# - name: Run mypy
# run: mypy pyesef
- name: Run mypy
run: |
source .venv/bin/activate
pre-commit run --hook-stage manual mypy --all-files --show-diff-on-failure
pytest:
name: Run test suite
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ repos:
- id: no-commit-to-branch
args:
- --branch=main
- repo: local
hooks:
- id: mypy
name: mypy
entry: >
./script/run-in-env.sh mypy --config-file pyproject.toml
language: script
types: [python]
require_serial: true
files: ^pygleif/.+\.py$
10 changes: 5 additions & 5 deletions pygleif/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ class Links(BaseSchema):
class Relationships(BaseSchema):
"""Represent a relationships ."""

managing_lou: Links = None
lei_issuer: Links = None
field_modifications: Links = None
direct_parent: Links = None
ultimate_parent: Links = None
managing_lou: Links | None = None
lei_issuer: Links | None = None
field_modifications: Links | None = None
direct_parent: Links | None = None
ultimate_parent: Links | None = None


class Data(BaseSchema):
Expand Down
4 changes: 2 additions & 2 deletions pygleif/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class PyGleifBase(ABC):
search_string: str

@property
def json_response(self) -> list[Any] | dict[Any, Any]:
def json_response(self) -> dict[Any, Any]:
"""Return JSON response."""
full_url = f"{self.BASE_URL}{self.search_string}"
try:
with request.urlopen(
full_url,
timeout=self.TIMEOUT_SECOND,
) as fdesc:
return cast(dict[Any, Any] | list[Any], json.loads(fdesc.read()))
return cast(dict[Any, Any], json.loads(fdesc.read()))
except error.HTTPError as e:
if e.code == HttpErrorCodes.NOT_FOUND:
raise PyGLEIFApiError(f"Resource {full_url} not found")
Expand Down
Empty file added pygleif/py.typed
Empty file.
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ version = {file = "pygleif/VERSION"}
[tool.setuptools.packages.find]
exclude = ["tests", "tests*"]

[tool.setuptools.package-data]
"pygleif" = ["py.typed"]

[tool.pytest.ini_options]
testpaths = [
"tests",
Expand Down Expand Up @@ -120,3 +123,8 @@ known-first-party = [
"pygleif",
"tests",
]

[tool.mypy]
python_version = "3.11"
strict = true
plugins = "pydantic.mypy"

0 comments on commit a6a0cb8

Please sign in to comment.