Skip to content

Commit 1794868

Browse files
author
Bas van Beek
committed
AssertionLib 2.2.1
1 parent 7a3351e commit 1794868

17 files changed

+291
-154
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,9 @@ venv.bak/
106106

107107
# Visual Studio Code
108108
.vscode/
109+
110+
# MyPy
109111
.mypy_cache/
110-
ipython.html
112+
html/
113+
index.html
114+
mypy-html.css

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ install:
3333
- conda info -a
3434

3535
# Install virtual enviroment
36-
- conda create -n assertionlib python=${PYTHON_VERSION} numpy
36+
- conda create -n assertionlib python=${PYTHON_VERSION}
3737
- source activate assertionlib
3838

3939
# Install the tests
4040
- pip install .[test]
4141

4242
script:
4343
# Run the unitary tests excluding the expensive computations
44-
- pytest -m "not (slow or long)" --cov=assertionlib tests
44+
- pytest --cov=assertionlib --mypy tests assertionlib
4545
- coverage xml && coverage report -m
4646

4747
branches:

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66
This project adheres to `Semantic Versioning <http://semver.org/>`_.
77

88

9+
2.2.1
10+
*****
11+
* Added a mypy test.
12+
* Further refined type annotations.
13+
14+
915
2.2.0
1016
*****
1117
* Marked AssertionLib as a typed package (`PEP 561 <https://www.python.org/dev/peps/pep-0561/>`_).

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
##################
19-
AssertionLib 2.2.0
19+
AssertionLib 2.2.1
2020
##################
2121

2222
A package for performing assertions and providing informative exception messages.

assertionlib/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.2.0'
1+
__version__ = '2.2.1'

assertionlib/dataclass.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def decorating_function(user_function: UserFunc) -> UserFunc:
6060
running: Set[Tuple[int, int]] = set()
6161

6262
@wraps(user_function)
63-
def wrapper(self, *args, **kwargs):
63+
def wrapper(self: Any, *args: Any, **kwargs: Any) -> T:
6464
key = id(self), get_ident()
6565
if key in running:
6666
return fallback(self, *args, **kwargs)
@@ -76,22 +76,22 @@ def wrapper(self, *args, **kwargs):
7676

7777

7878
class _MetaADC(ABCMeta):
79-
def __new__(mcls, name, bases, namespace, **kwargs) -> '_MetaADC':
80-
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
81-
if not cls._HASHABLE:
79+
def __new__(mcls, name, bases, namespace) -> '_MetaADC':
80+
cls = cast(_MetaADC, super().__new__(mcls, name, bases, namespace))
81+
if not cls._HASHABLE: # type: ignore
8282
setattr(cls, '__hash__', mcls._hash_template1)
8383
else:
84-
func = recursion_safeguard(cls._repr_fallback)(mcls._hash_template2)
84+
func = recursion_safeguard(cls._repr_fallback)(mcls._hash_template2) # type: ignore
8585
setattr(cls, '__hash__', func)
8686
return cls
8787

8888
@staticmethod
89-
def _hash_template1(self) -> NoReturn:
89+
def _hash_template1(self: Any) -> NoReturn:
9090
"""Unhashable type; raise a :exc:`TypeError`."""
9191
raise TypeError(f"Unhashable type: {self.__class__.__name__!r}")
9292

9393
@staticmethod
94-
def _hash_template2(self) -> int:
94+
def _hash_template2(self: Any) -> int:
9595
"""Return the hash of this instance.
9696
9797
The returned hash is constructed from two components:
@@ -338,7 +338,10 @@ def copy(self, deep: bool = False) -> 'AbstractDataClass':
338338
A new instance constructed from this instance.
339339
340340
"""
341-
copy_func = cast(Callable[[T], T], copy.deepcopy if deep else lambda n: n)
341+
def return_arg(arg: T) -> T:
342+
return arg
343+
344+
copy_func = cast(Callable[[T], T], copy.deepcopy if deep else return_arg)
342345

343346
cls = type(self)
344347
ret = cls.__new__(cls)
@@ -406,7 +409,7 @@ def from_dict(cls, dct: Mapping[str, Any]) -> 'AbstractDataClass':
406409
Construct a dictionary from this instance with all non-private instance variables.
407410
408411
"""
409-
return cls(**dct)
412+
return cls(**dct) # type: ignore
410413

411414
@classmethod
412415
def inherit_annotations(cls) -> Callable[[UserFunc], UserFunc]:

assertionlib/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _create_assertion_func(func: Callable) -> Tuple[types.FunctionType, str]:
132132
A callable object forming the basis of the to-be created assertion function.
133133
134134
"""
135-
_empty = inspect._empty
135+
_empty = inspect._empty # type: ignore
136136

137137
def _to_str(prm: inspect.Parameter) -> str:
138138
"""Create a string from **prm**; ensure that callables are represented by their __name__."""
@@ -346,7 +346,7 @@ def get_sphinx_domain(func: Callable, module_mapping: Mapping[str, str] = MODULE
346346
try:
347347
_module = func.__module__
348348
except AttributeError: # Unbound methods don't have the `__module__` attribute
349-
_module = func.__objclass__.__module__
349+
_module = func.__objclass__.__module__ # type: ignore
350350

351351
# Convert the extracted __module__ into an actual valid module
352352
module = MODULE_DICT.get(_module, _module)

assertionlib/manager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ def __new__(mcls, name, bases, namespace) -> '_MetaAM':
253253

254254
# On windows os.path.isdir is an alias for the ._isdir function
255255
if os.name == 'nt':
256-
cls.isdir = cls._isdir
257-
cls.isdir.__name__ = 'isdir'
258-
cls.isdir.__qualname__ = 'isdir'
259-
cls.isdir.__doc__ = cls.isdir.__doc__.replace('_isdir', 'isdir')
260-
del cls._isdir
256+
cls.isdir = cls._isdir # type: ignore
257+
cls.isdir.__name__ = 'isdir' # type: ignore
258+
cls.isdir.__qualname__ = 'isdir' # type: ignore
259+
cls.isdir.__doc__ = cls.isdir.__doc__.replace('_isdir', 'isdir') # type: ignore
260+
del cls._isdir # type: ignore
261261
return cls
262262

263263

@@ -349,7 +349,7 @@ def assert_(self, func: Callable[..., T], *args: Any, invert: bool = False,
349349
350350
Parameters
351351
----------
352-
func : :data:`coollections.abc.Callable`
352+
func : :class:`~collections.abc.Callable`
353353
The callable whose output will be evaluated.
354354
355355
\*args : :data:`~typing.Any`
@@ -607,7 +607,7 @@ def _get_exc_signature(signature: inspect.Signature, args: Sequence[str],
607607
608608
""" # noqa
609609
# Unpack parameters
610-
empty = inspect._empty
610+
empty = inspect._empty # type: ignore
611611
Parameter = inspect.Parameter
612612
parameters = signature.parameters
613613
kind = Parameter.POSITIONAL_OR_KEYWORD

0 commit comments

Comments
 (0)