From 912d579a2aef2028906ce28ff0431f3a932b08b1 Mon Sep 17 00:00:00 2001 From: Paul Andrey <paul.andrey@inria.fr> Date: Mon, 20 Jan 2025 16:09:36 +0100 Subject: [PATCH] Silence mypy warnings to be fixed when dropping py38 support. --- declearn/utils/_dataclass.py | 4 +++- declearn/utils/_toml_config.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/declearn/utils/_dataclass.py b/declearn/utils/_dataclass.py index 38e608ad..dc0c1b61 100644 --- a/declearn/utils/_dataclass.py +++ b/declearn/utils/_dataclass.py @@ -204,5 +204,7 @@ def _parameters_to_fields( ftype = Dict[str, ftype] # type: ignore field.default_factory = dict # Append parsed information to the fields list. - fields.append((fname, ftype, field)) + fields.append( + (fname, ftype, field) # type: ignore # update when py >=3.9 + ) return fields diff --git a/declearn/utils/_toml_config.py b/declearn/utils/_toml_config.py index a3c88602..bbbbb550 100644 --- a/declearn/utils/_toml_config.py +++ b/declearn/utils/_toml_config.py @@ -139,7 +139,7 @@ def _instantiate_field( origin = typing.get_origin(field.type) # Case of a raw type. if origin is None: - return _instantiate(field.type) + return _instantiate(field.type) # type: ignore # update when py >=3.9 # Case of a union of types (including optional). if origin is Union: for cls in typing.get_args(field.type): @@ -284,7 +284,9 @@ class TomlConfig: Instantiated object that matches the field's specifications. """ # Case of valid inputs: return them as-is (including valid None). - if _isinstance_generic(inputs, field.type): # see function's notes + if _isinstance_generic( + inputs, field.type # type: ignore # update when py >=3.9 + ): # see function's notes return inputs # Case of None inputs: return default value if any, else raise. if inputs is None: -- GitLab