From e710fa44b5e4994dfabb6ba104f7698b8b556e4f Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 20 Oct 2023 23:15:13 -0700 Subject: [PATCH] improve type annotations --- masque/library.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/masque/library.py b/masque/library.py index bee7537..96a6de4 100644 --- a/masque/library.py +++ b/masque/library.py @@ -26,7 +26,7 @@ from collections import defaultdict from abc import ABCMeta, abstractmethod import numpy -from numpy.typing import ArrayLike +from numpy.typing import ArrayLike, NDArray from .error import LibraryError, PatternError from .utils import rotation_matrix_2d, layer_t @@ -42,7 +42,16 @@ if TYPE_CHECKING: logger = logging.getLogger(__name__) -visitor_function_t = Callable[..., 'Pattern'] +class visitor_function_t(Protocol): + """ Signature for `Library.dfs()` visitor functions. """ + def __call__( + self, + pattern: 'Pattern', + hierarchy: tuple[str | None, ...], + memo: dict, + transform: NDArray[numpy.float64] | Literal[False], + ) -> Pattern: + ... TreeView: TypeAlias = Mapping[str, 'Pattern']