Skip to content

Commit acd82a1

Browse files
authored
Merge pull request #30 from nlesc-nano/310
TST: Add more python 3.10 tests
2 parents 843e866 + c7103a1 commit acd82a1

File tree

10 files changed

+59
-48
lines changed

10 files changed

+59
-48
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ jobs:
1717
fail-fast: False
1818
matrix:
1919
os: [ubuntu-latest, macos-latest, windows-latest]
20-
python-version: [3.6, 3.7, 3.8, 3.9]
20+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
2121
special: ['']
2222
include:
2323
- os: ubuntu-latest
2424
special: '; pre-release'
25-
python-version: 3.9
25+
python-version: "3.10"
2626
- os: ubuntu-latest
2727
special: '; no-optional'
28-
python-version: 3.9
29-
- os: ubuntu-latest
30-
special: '; no-optional'
31-
python-version: '3.10'
28+
python-version: "3.10"
3229

3330
steps:
3431
- name: Cancel Previous Runs
@@ -45,16 +42,15 @@ jobs:
4542

4643
- name: Install dependencies
4744
shell: bash
48-
env:
49-
SPECIAL: ${{ matrix.special }}
5045
run: |
51-
if [[ $SPECIAL == '; no-optional' ]]; then
52-
pip install -e .[test_no_optional]
53-
elif [[ $SPECIAL == '; pre-release' ]]; then
54-
pip install --pre -e .[test] --upgrade --force-reinstall
55-
else
56-
pip install -e .[test]
57-
fi
46+
case "${{ matrix.special }}" in
47+
'; no-optional')
48+
pip install -e .[test_no_optional] ;;
49+
'; pre-release')
50+
pip install --pre -e .[test] --upgrade --force-reinstall ;;
51+
*)
52+
pip install -e .[test] ;;
53+
esac
5854
5955
- name: Python info
6056
run: |
@@ -66,14 +62,13 @@ jobs:
6662

6763
- name: Test with pytest
6864
shell: bash
69-
env:
70-
SPECIAL: ${{ matrix.special }}
7165
run: |
72-
if [[ $SPECIAL == '; no-optional' ]]; then
73-
pytest --mypy
74-
else
75-
pytest --mypy --doctest-modules
76-
fi
66+
case "${{ matrix.special }}" in
67+
'; no-optional')
68+
pytest ;;
69+
*)
70+
pytest --doctest-modules ;;
71+
esac
7772
7873
- name: Run codecov
7974
uses: codecov/codecov-action@v2
@@ -86,13 +81,15 @@ jobs:
8681
steps:
8782
- uses: actions/checkout@v2
8883

89-
- name: Set up Python 3.9 on ubuntu-latest
84+
- name: Set up Python 3.10 on ubuntu-latest
9085
uses: actions/setup-python@v2
9186
with:
92-
python-version: 3.9
87+
python-version: "3.10"
9388

9489
- name: Install linters
95-
run: pip install flake8 pydocstyle
90+
run: |
91+
pip install flake8 pydocstyle mypy
92+
pip install --pre -e .[test] --upgrade
9693
9794
- name: Python info
9895
run: |
@@ -104,8 +101,9 @@ jobs:
104101

105102
- name: Run flake8
106103
run: flake8 docs assertionlib tests
107-
continue-on-error: true
108104

109105
- name: Run pydocstyle
110-
run: pydocstyle docs assertionlib tests
111-
continue-on-error: true
106+
run: pydocstyle assertionlib
107+
108+
- name: Run mypy
109+
run: mypy assertionlib tests

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
:target: https://docs.python.org/3.8/
2020
.. image:: https://img.shields.io/badge/python-3.9-blue.svg
2121
:target: https://docs.python.org/3.9/
22-
22+
.. image:: https://img.shields.io/badge/python-3.10-blue.svg
23+
:target: https://docs.python.org/3.10/
2324

2425
##################
2526
AssertionLib 3.2.1

assertionlib/assertion_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from types import FunctionType
2929
from itertools import zip_longest
3030
from typing import (
31+
Any,
3132
Sized,
3233
Callable,
3334
TypeVar,
@@ -64,7 +65,7 @@ def str_eq(a: T, b: str, *, str_converter: Callable[[T], str] = repr) -> bool:
6465

6566

6667
@to_positional
67-
def shape_eq(a: ndarray, b: Union[ndarray, Tuple[int, ...]]) -> bool:
68+
def shape_eq(a: "ndarray[Any, Any]", b: Union["ndarray[Any, Any]", Tuple[int, ...]]) -> bool:
6869
"""Check if the shapes of **a** and **b** are equivalent: :code:`a.shape == getattr(b, 'shape', b)`.
6970
7071
**b** should be either an object with the ``shape`` attribute (*e.g.* a NumPy array)

assertionlib/dataclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def decorating_function(user_function: FT) -> FT:
5858
running: Set[Tuple[int, int]] = set()
5959

6060
@wraps(user_function)
61-
def wrapper(self, *args: Any, **kwargs: Any) -> Any:
61+
def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
6262
key = id(self), get_ident()
6363
if key in running:
6464
return fallback(self, *args, **kwargs)

assertionlib/functions.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def to_positional(func: FT) -> FT:
133133
return func
134134

135135

136-
def bind_callable(class_type: Union[type, Any], func: Callable,
136+
def bind_callable(class_type: Union[type, Any], func: Callable[..., Any],
137137
name: Optional[str] = None, warn: bool = True) -> None:
138138
"""Take a callable and use it to create a new assertion method for **class_type**.
139139
@@ -184,7 +184,7 @@ def bind_callable(class_type: Union[type, Any], func: Callable,
184184
def create_assertion_func(func: Callable[..., Any]) -> Callable[..., None]:
185185
"""Construct an assertion function from **func**."""
186186

187-
def wrapper(self, *args: Any,
187+
def wrapper(self: Any, *args: Any,
188188
invert: bool = False,
189189
exception: Optional[Type[Exception]] = None,
190190
post_process: Optional[Callable[[Any], Any]] = None,
@@ -250,7 +250,7 @@ def wrapper(self, *args: Any,
250250
"""
251251

252252

253-
def create_assertion_doc(func: Callable) -> str:
253+
def create_assertion_doc(func: Callable[..., Any]) -> str:
254254
r"""Create a new NumPy style assertion docstring from the docstring of **func**.
255255
256256
The summary of **funcs'** docstring, if available, is added to the ``"See also"`` section,
@@ -343,19 +343,22 @@ def create_assertion_doc(func: Callable) -> str:
343343

344344

345345
#: A dictionary which translates certain __module__ values to an actual valid modules
346-
MODULE_DICT: Mapping[str, str] = MappingProxyType({
346+
MODULE_DICT = MappingProxyType({
347347
'genericpath': 'os.path',
348348
'posixpath': 'os.path',
349349
'_operator': 'operator'
350350
})
351351

352352

353-
def _is_builtin_func(func: Callable) -> bool:
353+
def _is_builtin_func(func: Callable[..., Any]) -> bool:
354354
"""Check if **func** is a builtin function."""
355355
return isbuiltin(func) and '.' not in getattr(func, '__qualname__', '')
356356

357357

358-
def get_sphinx_domain(func: Callable, module_mapping: Mapping[str, str] = MODULE_DICT) -> str:
358+
def get_sphinx_domain(
359+
func: Callable[..., Any],
360+
module_mapping: Mapping[str, str] = MODULE_DICT,
361+
) -> str:
359362
"""Create a Sphinx domain for **func**.
360363
361364
Examples
@@ -440,7 +443,7 @@ def get_sphinx_domain(func: Callable, module_mapping: Mapping[str, str] = MODULE
440443
})
441444

442445

443-
def load_readme(readme: Union[str, bytes, int, os.PathLike],
446+
def load_readme(readme: Union[str, bytes, int, "os.PathLike[str]", "os.PathLike[bytes]"],
444447
replace: Mapping[str, str] = README_MAPPING,
445448
**kwargs: Any) -> str:
446449
r"""Load and return the content of a readme file located in the same directory as this file.

assertionlib/ndrepr.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@
7979
)
8080

8181

82-
from nanoutils import raise_if
83-
84-
from .functions import set_docstring
82+
from nanoutils import raise_if, set_docstring
8583

8684
if TYPE_CHECKING:
8785
import numpy as np
@@ -367,7 +365,7 @@ def repr_Signature(self, obj: inspect.Signature, level: int) -> str: # noqa: N8
367365

368366
return f'{param_accumulate}){ret}'
369367

370-
def _parse_callable(self, obj: Callable, level: int) -> Tuple[str, str]:
368+
def _parse_callable(self, obj: Callable[..., Any], level: int) -> Tuple[str, str]:
371369
"""Create a :class:`str` representation of the name and signature of a callable."""
372370
# Construct the name of the callable
373371
name: str = getattr(obj, '__qualname__', obj.__name__)
@@ -462,7 +460,7 @@ def repr_Bond(self, obj: Bond, level: int) -> str: # noqa: N802
462460
# NumPy- and Pandas-related methods
463461

464462
@raise_if(NUMPY_EX)
465-
def repr_ndarray(self, obj: ndarray, level: int) -> str:
463+
def repr_ndarray(self, obj: "ndarray[Any, Any]", level: int) -> str:
466464
"""Create a :class:`str` representation of a :class:`numpy.ndarray` instance."""
467465
if level <= 0:
468466
return f'{obj.__class__.__name__}(...)'
@@ -510,7 +508,7 @@ def repr_Dataset(self, obj: Dataset, level: int) -> str: # noqa: N802
510508
"""Create a :class:`str` representation of a :class:`h5py.Dataset` instance."""
511509
return repr(obj)
512510

513-
def _get_ndformatter(self, obj: ndarray) -> _FormatDict:
511+
def _get_ndformatter(self, obj: "ndarray[Any, Any]") -> _FormatDict:
514512
"""Return a value for the **formatter** argument in :func:`numpy.printoptions`."""
515513
if obj.dtype != float and obj.dtype != int:
516514
return {}

mypy.ini

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
[mypy]
2-
ignore_missing_imports = True
32
warn_unused_ignores = True
43
warn_redundant_casts = True
54
warn_return_any = True
65
show_error_codes = True
6+
7+
[mypy-scm.*]
8+
ignore_missing_imports = True
9+
10+
[mypy-pandas.*]
11+
ignore_missing_imports = True
12+
13+
[mypy-h5py.*]
14+
ignore_missing_imports = True
15+
16+
[mypy-wheel.*]
17+
ignore_missing_imports = True

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
description-file = README.rst
2+
description_file = README.rst
33
license_files = LICENSE.md
44

55
[aliases]

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
tests_require_no_optional = [
3232
'pytest>=5.4.0',
3333
'pytest-cov',
34-
'pytest-mypy>=0.6.2',
3534
]
3635

3736
# Requirements for running tests

tests/test_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from nanoutils import delete_finally
77

88
try:
9-
import wheel
9+
import wheel # noqa: F401
1010
except ModuleNotFoundError as ex:
1111
WHEEL_EX: "None | ModuleNotFoundError" = ex
1212
else:

0 commit comments

Comments
 (0)