Skip to content

Commit

Permalink
migrated type checking to pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
mbsantiago committed May 10, 2024
1 parent ceed73c commit 08360c0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
run: |
sudo apt-get update && sudo apt-get install libsndfile1
python -m pip install --upgrade pip
python -m pip install pytest hypothesis ruff mypy black html5lib
python -m pip install pytest hypothesis ruff pyright html5lib
python -m pip install ".[all]"
- name: Make sure types are consistent
run: mypy --ignore-missing-imports src
run: pyright src
- name: Lint with ruff
run: ruff src
run: ruff check src
- name: Test with pytest
run: pytest tests
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ fmt: ## Format code using black & isort.
$(ENV_PREFIX)ruff format $(PROJECT_NAME)/
$(ENV_PREFIX)ruff format tests/

.PHONY: lint
lint: ## Run ruff, black, mypy linters.
.PHONY: lint-mypy
lint-pyright:
$(ENV_PREFIX)pyright $(PROJECT_NAME)/

.PHONY: lint-ruff
lint-ruff:
$(ENV_PREFIX)ruff check $(PROJECT_NAME)/
$(ENV_PREFIX)ruff check tests/
$(ENV_PREFIX)mypy $(PROJECT_NAME)/ --config-file pyproject.toml

.PHONY: lint
lint: lint-mypy lint-ruff

.PHONY: test-watch
test-watch: ## Run tests and generate coverage report.
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ rye = { dev-dependencies = [
"icecream>=2.1.3",
"pytest>=7.4.0",
"coverage[toml]>=7.3.2",
"black>=23.3.0",
"mypy>=1.4.1",
"pytest-coverage>=0.0",
"mkdocs>=1.2.4",
"importlib-metadata>=4.3",
Expand All @@ -57,6 +55,7 @@ rye = { dev-dependencies = [
"pytest-watch>=4.2.0",
"pytest-testmon>=2.0.12",
"html5lib>=1.1",
"pyright>=1.1.362",
] }

[tool.pytest.ini_options]
Expand Down
17 changes: 5 additions & 12 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ babel==2.14.0
# via mkdocs-material
birdsong-recognition-dataset==0.3.2.post1
# via crowsetta
black==24.4.2
cachetools==5.3.3
# via tox
certifi==2024.2.2
Expand All @@ -35,7 +34,6 @@ chardet==5.2.0
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via black
# via mkdocs
# via mkdocstrings
colorama==0.4.6
Expand Down Expand Up @@ -143,11 +141,10 @@ mkdocstrings-python==1.10.0
# via mkdocstrings
multimethod==1.10
# via pandera
mypy==1.10.0
mypy-extensions==1.0.0
# via black
# via mypy
# via typing-inspect
nodeenv==1.8.0
# via pyright
numpy==1.24.4
# via birdsong-recognition-dataset
# via contourpy
Expand All @@ -161,7 +158,6 @@ numpy==1.24.4
# via shapely
# via xarray
packaging==24.0
# via black
# via matplotlib
# via mkdocs
# via mkdocs-gallery
Expand All @@ -179,12 +175,10 @@ pandas==2.0.3
pandera==0.18.3
# via crowsetta
pathspec==0.12.1
# via black
# via mkdocs
pillow==10.3.0
# via matplotlib
platformdirs==4.2.1
# via black
# via mkdocs-get-deps
# via mkdocstrings
# via tox
Expand All @@ -211,6 +205,7 @@ pyparsing==3.1.2
# via matplotlib
pyproject-api==1.6.1
# via tox
pyright==1.1.362
pytest==8.1.2
# via pytest-cov
# via pytest-testmon
Expand Down Expand Up @@ -248,6 +243,8 @@ scipy==1.10.1
# via evfuncs
# via scikit-learn
# via soundevent
setuptools==69.5.1
# via nodeenv
shapely==2.0.4
# via soundevent
six==1.16.0
Expand All @@ -263,9 +260,7 @@ soundfile==0.12.1
threadpoolctl==3.4.0
# via scikit-learn
tomli==2.0.1
# via black
# via coverage
# via mypy
# via pyproject-api
# via pytest
# via tox
Expand All @@ -276,9 +271,7 @@ typeguard==4.2.1
# via pandera
typing-extensions==4.11.0
# via annotated-types
# via black
# via mkdocstrings
# via mypy
# via pydantic
# via pydantic-core
# via typeguard
Expand Down
2 changes: 1 addition & 1 deletion src/soundevent/data/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ def geometry_validate(
if not hasattr(obj, "type"):
raise ValueError(f"Object {obj} does not have a type attribute.")

geom_type = obj.type
geom_type = obj.type # type: ignore

if geom_type not in GEOMETRY_MAPPING:
raise ValueError(f"Object {obj} does not have a geometry valid type.")
Expand Down
4 changes: 2 additions & 2 deletions src/soundevent/io/crowsetta/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


LabelToTagFn = Callable[[str], Union[List[data.Tag], data.Tag]]
LabelToTagMap = dict[str, Union[List[data.Tag], data.Tag]]
LabelToTagMap = Dict[str, Union[List[data.Tag], data.Tag]]


def label_to_tags(
Expand Down Expand Up @@ -110,7 +110,7 @@ def label_to_tags(
def label_from_tag(
tag: data.Tag,
label_fn: Optional[Callable[[data.Tag], str]] = None,
label_mapping: Optional[dict[data.Tag, str]] = None,
label_mapping: Optional[Dict[data.Tag, str]] = None,
value_only: bool = False,
separator: str = ":",
) -> str:
Expand Down

0 comments on commit 08360c0

Please sign in to comment.