Skip to content

Commit

Permalink
Add typing annotations (#72)
Browse files Browse the repository at this point in the history
* Add typing annotations

* Update CI

* Pymake issue is not yet fixed in the latest release

* Sort imports

* Use typing syntax that is compatible with <3.10

* Extend typing

* CI: Ignore missing imports

* Fix types

* Add type annotation

* Ignore last type errors

* Install types before running mypy

* Finish up CI

* Export types

* Add more annotations

* Add more types
  • Loading branch information
Hofer-Julian authored Mar 28, 2022
1 parent f929fbb commit ed8d4c2
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 86 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
run: |
sudo ln -fs /usr/bin/gfortran-10 /usr/local/bin/gfortran
gfortran --version
# Remove as soon as https://github.com/modflowpy/pymake/issues/111 is fixed
- name: Install numpy
run: |
pip install numpy
- name: Install and print system dependencies (macOS)
shell: bash
if: runner.os == 'macOS'
Expand All @@ -40,10 +44,6 @@ jobs:
if: runner.os == 'Windows'
run: |
gfortran --version
# Remove as soon as https://github.com/modflowpy/pymake/issues/111 is fixed
- name: Install numpy
run: |
pip install numpy
- name: Install test dependencies
run: |
pip install -e ".[tests]"
Expand All @@ -59,16 +59,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install lint dependencies
run: |
pip install -e ".[lint]"
- name: Run black
run: black --check .
- name: Run isort
run: isort --check .
- name: Run flake8
run: flake8
- name: Run mypy
run: |
mypy --install-types --non-interactive --ignore-missing-imports .
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ def get_version(rel_path):
extras_require={
"tests": ["pytest", "pytest-cov", "requests", "mfpymake", "flopy"],
"lint": [
"flake8",
"mypy",
"black",
"isort",
],
},
python_requires=">=3.7",
packages=find_namespace_packages(exclude=("tests", "examples")),
package_data={"xmipy": ["py.typed"]},
version=get_version("xmipy/__init__.py"),
classifiers=["Topic :: Scientific/Engineering :: Hydrology"],
zip_safe=False,
)
6 changes: 3 additions & 3 deletions xmipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# imports
from xmipy.xmi import Xmi
from xmipy.xmiwrapper import XmiWrapper
from xmipy.xmi import Xmi as Xmi
from xmipy.xmiwrapper import XmiWrapper as XmiWrapper

__version__ = "1.0.0"
__version__ = "1.1"
Empty file added xmipy/py.typed
Empty file.
4 changes: 1 addition & 3 deletions xmipy/timers/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Adapted from https://pypi.org/project/codetiming/.
"""

# Standard library imports
import functools
import logging
import math
import time
Expand All @@ -21,7 +19,7 @@ class Timer:
def __init__(self, name: str, text: str):
self.name = name
self.timers = Timers()
self._start_time = {}
self._start_time: dict[str, float] = {}
self.text = text
self.last = math.nan

Expand Down
7 changes: 4 additions & 3 deletions xmipy/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
from contextlib import contextmanager
from pathlib import Path


@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
def cd(newdir: Path):
prevdir = Path().cwd()
os.chdir(newdir)
try:
yield
finally:
Expand Down
8 changes: 4 additions & 4 deletions xmipy/xmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Xmi(Bmi):
"""

@abstractmethod
def prepare_time_step(self, dt) -> None:
def prepare_time_step(self, dt: float) -> None:
""" """
...

Expand All @@ -41,16 +41,16 @@ def get_subcomponent_count(self) -> int:
...

@abstractmethod
def prepare_solve(self, component_id) -> None:
def prepare_solve(self, component_id: int) -> None:
""" """
...

@abstractmethod
def solve(self, component_id) -> bool:
def solve(self, component_id: int) -> bool:
""" """
...

@abstractmethod
def finalize_solve(self, component_id) -> None:
def finalize_solve(self, component_id: int) -> None:
""" """
...
Loading

0 comments on commit ed8d4c2

Please sign in to comment.