Skip to content

Commit

Permalink
return None
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Jan 18, 2025
1 parent 74b7086 commit 9b6b384
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 25 deletions.
8 changes: 4 additions & 4 deletions pint/facets/context/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pint/facets/dask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pint/facets/group/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pint/facets/group/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions pint/facets/numpy/numpy_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pint/facets/numpy/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pint/facets/plain/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions pint/facets/system/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion pint/facets/system/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
# ]

0 comments on commit 9b6b384

Please sign in to comment.