diff --git a/pint/facets/context/objects.py b/pint/facets/context/objects.py index edd1dfb2a..3e9e56d06 100644 --- a/pint/facets/context/objects.py +++ b/pint/facets/context/objects.py @@ -240,7 +240,7 @@ def redefine(self, definition: str) -> None: if isinstance(definition, UnitDefinition): self._redefine(definition) - def _redefine(self, definition: UnitDefinition): + def _redefine(self, definition: UnitDefinition) -> None: self.redefinitions.append(definition) def hashable( @@ -274,13 +274,13 @@ class ContextChain(ChainMap[SrcDst, Context]): to transform from one dimension to another. """ - def __init__(self): + def __init__(self) -> None: super().__init__() self.contexts: list[Context] = [] self.maps.clear() # Remove default empty map self._graph: dict[SrcDst, set[UnitsContainer]] | None = None - def insert_contexts(self, *contexts: Context): + def insert_contexts(self, *contexts: Context) -> None: """Insert one or more contexts in reversed order the chained map. (A rule in last context will take precedence) @@ -292,7 +292,7 @@ def insert_contexts(self, *contexts: Context): self.maps = [ctx.relation_to_context for ctx in reversed(contexts)] + self.maps self._graph = None - def remove_contexts(self, n: int | None = None): + def remove_contexts(self, n: int | None = None) -> None: """Remove the last n inserted contexts from the chain. Parameters diff --git a/pint/facets/dask/__init__.py b/pint/facets/dask/__init__.py index c3133bc31..91e0b5ee1 100644 --- a/pint/facets/dask/__init__.py +++ b/pint/facets/dask/__init__.py @@ -110,7 +110,7 @@ def persist(self, **kwargs): return result @check_dask_array - def visualize(self, **kwargs): + def visualize(self, **kwargs) -> None: """Produce a visual representation of the Dask graph. The graphviz library is required. diff --git a/pint/facets/group/objects.py b/pint/facets/group/objects.py index 751dd3765..5c82aca41 100644 --- a/pint/facets/group/objects.py +++ b/pint/facets/group/objects.py @@ -58,7 +58,7 @@ class Group(SharedRegistryObject): If not given, a root Group will be created. """ - def __init__(self, name: str): + def __init__(self, name: str) -> None: # The name of the group. self.name = name diff --git a/pint/facets/group/registry.py b/pint/facets/group/registry.py index 33f78c645..cb72753cc 100644 --- a/pint/facets/group/registry.py +++ b/pint/facets/group/registry.py @@ -44,7 +44,7 @@ class GenericGroupRegistry( # to enjoy typing goodies Group = type[objects.Group] - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: super().__init__(**kwargs) #: Map group name to group. self._groups: dict[str, objects.Group] = {} @@ -81,7 +81,7 @@ def _register_definition_adders(self) -> None: super()._register_definition_adders() self._register_adder(GroupDefinition, self._add_group) - def _add_unit(self, definition: UnitDefinition): + def _add_unit(self, definition: UnitDefinition) -> None: super()._add_unit(definition) # TODO: delta units are missing self.get_group("root").add_units(definition.name) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index b79700f9f..fd27c5e1c 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -247,7 +247,7 @@ def decorator(func): return decorator -def implement_func(func_type, func_str, input_units=None, output_unit=None): +def implement_func(func_type, func_str, input_units=None, output_unit=None) -> None: """Add default-behavior NumPy function/ufunc to the handled list. Parameters @@ -597,7 +597,7 @@ def _unwrap(p, discont=None, axis=-1): @implements("copyto", "function") -def _copyto(dst, src, casting="same_kind", where=True): +def _copyto(dst, src, casting="same_kind", where=True) -> None: if _is_quantity(dst): if _is_quantity(src): src = src.m_as(dst.units) @@ -700,7 +700,7 @@ def _all(a, *args, **kwargs): raise ValueError("Boolean value of Quantity with offset unit is ambiguous.") -def implement_prod_func(name): +def implement_prod_func(name) -> None: if np is None: return @@ -788,7 +788,7 @@ def _correlate(a, v, mode="valid", **kwargs): return a.units._REGISTRY.Quantity(ret, units) -def implement_mul_func(func): +def implement_mul_func(func) -> None: # If NumPy is not available, do not attempt implement that which does not exist if np is None: return @@ -815,7 +815,7 @@ def implementation(a, b, **kwargs): # Implement simple matching-unit or stripped-unit functions based on signature -def implement_consistent_units_by_argument(func_str, unit_arguments, wrap_output=True): +def implement_consistent_units_by_argument(func_str, unit_arguments, wrap_output=True) -> None: # If NumPy is not available, do not attempt implement that which does not exist if np is None: return @@ -916,7 +916,7 @@ def implementation(*args, **kwargs): # implement isclose and allclose -def implement_close(func_str): +def implement_close(func_str) -> None: if np is None: return @@ -950,7 +950,7 @@ def implementation(*args, **kwargs): # Handle atleast_nd functions -def implement_atleast_nd(func_str): +def implement_atleast_nd(func_str) -> None: # If NumPy is not available, do not attempt implement that which does not exist if np is None: return @@ -979,7 +979,7 @@ def implementation(*arrays): # Handle cumulative products (which must be dimensionless for consistent units across # output array) -def implement_single_dimensionless_argument_func(func_str): +def implement_single_dimensionless_argument_func(func_str) -> None: # If NumPy is not available, do not attempt implement that which does not exist if np is None: return diff --git a/pint/facets/numpy/quantity.py b/pint/facets/numpy/quantity.py index 75dccec54..f1d56b478 100644 --- a/pint/facets/numpy/quantity.py +++ b/pint/facets/numpy/quantity.py @@ -179,7 +179,7 @@ def dtype(self): return self._magnitude.dtype @shape.setter - def shape(self, value): + def shape(self, value) -> None: self._magnitude.shape = value def searchsorted(self, v, side="left", sorter=None): @@ -207,7 +207,7 @@ def prod(self, *args, **kwargs): """ return np.prod(self, *args, **kwargs) - def __ito_if_needed(self, to_units): + def __ito_if_needed(self, to_units) -> None: if self.unitless and to_units == "radian": return diff --git a/pint/facets/plain/definitions.py b/pint/facets/plain/definitions.py index a43ce0dbc..edf122149 100644 --- a/pint/facets/plain/definitions.py +++ b/pint/facets/plain/definitions.py @@ -24,7 +24,7 @@ class NotNumeric(Exception): """Internal exception. Do not expose outside Pint""" - def __init__(self, value: Any): + def __init__(self, value: Any) -> None: self.value = value diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index be70a2ca8..f1fa16387 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -231,7 +231,7 @@ def __init__( cache_folder: str | pathlib.Path | None = None, separate_format_defaults: bool | None = None, mpl_formatter: str = "{:P}", - ): + ) -> None: #: Map a definition class to a adder methods. self._adders: Handler = {} self._register_definition_adders() @@ -415,7 +415,7 @@ def fmt_locale(self) -> Locale | None: "This function will be removed in future versions of pint.\n" "Use ureg.formatter.set_locale" ) - def fmt_locale(self, loc: str | None): + def fmt_locale(self, loc: str | None) -> None: self.formatter.set_locale(loc) @deprecated( diff --git a/pint/facets/system/objects.py b/pint/facets/system/objects.py index 751a66abf..b5367b3b3 100644 --- a/pint/facets/system/objects.py +++ b/pint/facets/system/objects.py @@ -54,7 +54,7 @@ class System(SharedRegistryObject): Name of the group. """ - def __init__(self, name: str): + def __init__(self, name: str) -> None: #: Name of the system #: :type: str self.name = name @@ -103,7 +103,7 @@ def members(self): return self._computed_members - def invalidate_members(self): + def invalidate_members(self) -> None: """Invalidate computed members in this Group and all parent nodes.""" self._computed_members = None @@ -205,7 +205,7 @@ def from_definition( class Lister: - def __init__(self, d: dict[str, Any]): + def __init__(self, d: dict[str, Any]) -> None: self.d = d def __dir__(self) -> list[str]: diff --git a/pint/facets/system/registry.py b/pint/facets/system/registry.py index e5235a4cb..c614348e5 100644 --- a/pint/facets/system/registry.py +++ b/pint/facets/system/registry.py @@ -51,7 +51,7 @@ class GenericSystemRegistry( # to enjoy typing goodies System: type[objects.System] - def __init__(self, system: str | None = None, **kwargs): + def __init__(self, system: str | None = None, **kwargs) -> None: super().__init__(**kwargs) #: Map system name to system. diff --git a/pyproject.toml b/pyproject.toml index 9f29f8f92..819ed717a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,3 +104,18 @@ ignore = [ # line break before binary operator # "W503" ] + +# Configuration for mypy +# https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file +[tool.mypy] +# python_version = "3.9" +# follow_imports = "skip" +ignore_missing_imports = true +files = "pint/facets" # directory mypy should analyze +# # Directories to exclude from mypy's analysis +# exclude = [ +# "pint/testsuite", +# "docs", +# "pint/default_en.txt", +# "pint/constants_en.txt", +# ] \ No newline at end of file