diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 32db049051..1f0d1cfaa0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -25,7 +25,8 @@ jobs: pip install pipenv - name: Pipenv install requirements and check it can be locked run: | - pipenv install --dev --skip-lock --clear + pipenv --clear + pipenv install --dev --skip-lock pipenv run pip install -e .[all] pipenv run pip install --no-deps file:plugins/aea-ledger-ethereum pipenv run pip install --no-deps file:plugins/aea-ledger-cosmos diff --git a/Makefile b/Makefile index e1be44b9c8..31d3a99116 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ new_env: clean if [ -z "$v" ];\ then\ pipenv --rm;\ + pipenv --clear;\ pipenv --python 3.10;\ pipenv install --dev --skip-lock;\ pipenv run pip install -e .[all];\ diff --git a/Pipfile b/Pipfile index fff3c133d3..4fa9d6d80d 100644 --- a/Pipfile +++ b/Pipfile @@ -39,11 +39,11 @@ mistune = "==2.0.0a4" mkdocs = "==1.3.0" mkdocs-material = "==8.2.8" mkdocs-mermaid-plugin = {git = "https://github.com/pugong/mkdocs-mermaid-plugin.git"} -mypy = "==0.782" +mypy = "==0.910" numpy = ">=1.18.1" openapi-core = "==0.13.2" openapi-spec-validator = "==0.2.8" -packaging = "==20.9" +packaging = "==21.3" pexpect = "==4.8.0" protobuf = "==3.19.4" psutil = "==5.7.0" diff --git a/aea/cli/ipfs_hash.py b/aea/cli/ipfs_hash.py index 5f594f2ab4..79ca7a4aca 100644 --- a/aea/cli/ipfs_hash.py +++ b/aea/cli/ipfs_hash.py @@ -233,9 +233,7 @@ def update_hashes( extend_public_ids(item_config, public_id_to_hash_mappings) dump_yaml(config_file, item_config, extra_config) - configuration_obj = config_loader( - package_id.package_type.value, package_path - ) + configuration_obj = config_loader(package_id.package_type, package_path) sort_configuration_file(configuration_obj) update_fingerprint(configuration_obj) key, package_hash = hash_package( diff --git a/aea/cli/utils/click_utils.py b/aea/cli/utils/click_utils.py index a1f16b5d52..57d902dbb6 100644 --- a/aea/cli/utils/click_utils.py +++ b/aea/cli/utils/click_utils.py @@ -22,7 +22,7 @@ import os from collections import OrderedDict from pathlib import Path -from typing import Any, Callable, List, Optional, Union +from typing import Any, Callable, List, Optional, Union, cast import click from click import argument, option @@ -132,7 +132,7 @@ def convert( if parsed_value is None: self.fail(value, param, ctx) - return parsed_value + return cast(Path, parsed_value) class PublicIdParameter(click.ParamType): @@ -169,7 +169,7 @@ def convert(self, value: str, param: Any, ctx: Optional[click.Context]) -> Publi if parsed is None: self.fail(value, param, ctx) - return parsed + return cast(PublicId, parsed) class AgentDirectory(click.Path): diff --git a/aea/components/base.py b/aea/components/base.py index 2b4cd20e9e..8ae6f794f2 100644 --- a/aea/components/base.py +++ b/aea/components/base.py @@ -23,8 +23,9 @@ import sys import types from abc import ABC +from importlib.machinery import ModuleSpec from pathlib import Path -from typing import Any, Optional +from typing import Any, Optional, cast from aea.configurations.base import ( ComponentConfiguration, @@ -178,7 +179,7 @@ def perform_load_aea_package( import_path = prefix_pkg + "." + ".".join(relative_parent_dir.parts) spec = importlib.util.spec_from_file_location(import_path, subpackage_init_file) - module = importlib.util.module_from_spec(spec) + module = importlib.util.module_from_spec(cast(ModuleSpec, spec)) sys.modules[import_path] = module _default_logger.debug(f"loading {import_path}: {module}") spec.loader.exec_module(module) # type: ignore diff --git a/aea/helpers/base.py b/aea/helpers/base.py index 37d174b442..f8f181b1b1 100644 --- a/aea/helpers/base.py +++ b/aea/helpers/base.py @@ -91,12 +91,12 @@ def locate(path: str) -> Any: module_location = os.path.join(file_location, "__init__.py") spec = importlib.util.spec_from_file_location(spec_name, module_location) _default_logger.debug("Trying to import {}".format(module_location)) - nextmodule = _get_module(spec) + nextmodule = _get_module(cast(ModuleSpec, spec)) if nextmodule is None: module_location = file_location + ".py" spec = importlib.util.spec_from_file_location(spec_name, module_location) _default_logger.debug("Trying to import {}".format(module_location)) - nextmodule = _get_module(spec) + nextmodule = _get_module(cast(ModuleSpec, spec)) if nextmodule: module, n = nextmodule, n + 1 @@ -125,7 +125,7 @@ def load_module(dotted_path: str, filepath: Path) -> types.ModuleType: :raises Exception: if the execution of the module raises exception. # noqa: DAR402 """ spec = importlib.util.spec_from_file_location(dotted_path, str(filepath)) - module = importlib.util.module_from_spec(spec) + module = importlib.util.module_from_spec(cast(ModuleSpec, spec)) spec.loader.exec_module(module) # type: ignore return module @@ -530,7 +530,7 @@ def find_topological_order(adjacency_list: Dict[T, Set[T]]) -> List[T]: # compute the topological order queue: Deque[T] = deque() order = [] - queue.extendleft(sorted(roots)) + queue.extendleft(sorted(roots)) # type: ignore while len(queue) > 0: current = queue.pop() order.append(current) diff --git a/aea/protocols/dialogue/base.py b/aea/protocols/dialogue/base.py index 4061bdfa9c..e82379e7d9 100644 --- a/aea/protocols/dialogue/base.py +++ b/aea/protocols/dialogue/base.py @@ -230,7 +230,7 @@ class _DialogueMeta(type): def __new__(cls, name: str, bases: Tuple[Type], dct: Dict) -> "_DialogueMeta": """Construct a new type.""" # set class level `_rules` - dialogue_cls: Type[Dialogue] = super().__new__(cls, name, bases, dct) + dialogue_cls: Type[Dialogue] = super().__new__(cls, name, bases, dct) # type: ignore dialogue_cls._rules = dialogue_cls.Rules( dialogue_cls.INITIAL_PERFORMATIVES, dialogue_cls.TERMINAL_PERFORMATIVES, diff --git a/examples/gym_ex/gyms/env.py b/examples/gym_ex/gyms/env.py index 55742ca443..900b993357 100644 --- a/examples/gym_ex/gyms/env.py +++ b/examples/gym_ex/gyms/env.py @@ -36,7 +36,7 @@ Done = bool Info = dict -Feedback = Tuple[Observation, Reward, Done, Info] +Feedback = Tuple[Observation, Reward, Done, Info] # type: ignore class BanditEnv(gym.Env): @@ -72,7 +72,7 @@ def __init__( self.seed() # seed environment randomness @staticmethod - def reset() -> Observation: + def reset() -> Observation: # type: ignore """ Reset the environment. diff --git a/examples/gym_ex/proxy/env.py b/examples/gym_ex/proxy/env.py index bf17874fb1..f0a5c0f8ca 100755 --- a/examples/gym_ex/proxy/env.py +++ b/examples/gym_ex/proxy/env.py @@ -85,6 +85,8 @@ def role_from_first_message( # pylint: disable=unused-argument class ProxyEnv(gym.Env): """This class implements a proxy gym environment.""" + _agent_thread: Optional[Thread] + def __init__(self, gym_env: gym.Env) -> None: """ Instantiate the proxy environment. @@ -106,7 +108,7 @@ def __init__(self, gym_env: gym.Env) -> None: @property def active_dialogue(self) -> GymDialogue: """Get the active dialogue.""" - return self._active_dialogue + return cast(GymDialogue, self._active_dialogue) def step(self, action: Action) -> Feedback: """ @@ -143,7 +145,7 @@ def render(self, mode="human") -> None: :param mode: the run mode """ - self._agent.runtime.multiplexer.default_connection.channel.gym_env.render(mode) + self._agent.runtime.multiplexer.default_connection.channel.gym_env.render(mode) # type: ignore def reset(self) -> None: """Reset the environment.""" @@ -160,7 +162,7 @@ def reset(self) -> None: # Wait (blocking!) for the response envelope from the environment in_envelope = self._queue.get(block=True, timeout=None) # type: GymMessage - self._decode_status(in_envelope) + self._decode_status(cast(Envelope, in_envelope)) def close(self) -> None: """Close the environment.""" @@ -177,9 +179,9 @@ def close(self) -> None: def _connect(self): """Connect to this proxy environment. It starts a proxy agent that can interact with the framework.""" - if self._agent_thread.is_alive(): + if cast(Thread, self._agent_thread).is_alive(): raise ValueError("Agent already running.") - self._agent_thread.start() + cast(Thread, self._agent_thread).start() while not self._agent.runtime.is_running: # check agent completely running time.sleep(0.01) @@ -187,7 +189,7 @@ def _connect(self): def _disconnect(self): """Disconnect from this proxy environment. It stops the proxy agent and kills its thread.""" self._agent.stop() - self._agent_thread.join() + cast(Thread, self._agent_thread).join() self._agent_thread = None def _encode_and_send_action(self, action: Action, step_id: int) -> None: diff --git a/examples/gym_ex/rl/agent.py b/examples/gym_ex/rl/agent.py index 24881dec8f..57ecbef250 100644 --- a/examples/gym_ex/rl/agent.py +++ b/examples/gym_ex/rl/agent.py @@ -36,7 +36,7 @@ Done = bool Info = dict -Feedback = Tuple[Observation, Reward, Done, Info] +Feedback = Tuple[Observation, Reward, Done, Info] # type: ignore class PriceBandit: @@ -140,7 +140,7 @@ def _pick_an_action(self) -> Action: def _update_model( # pylint: disable=unused-argument self, - observation: Observation, + observation: Observation, # type: ignore reward: Reward, done: Done, info: Info, diff --git a/scripts/check_imports_and_dependencies.py b/scripts/check_imports_and_dependencies.py index 3e488d1c55..94250be069 100755 --- a/scripts/check_imports_and_dependencies.py +++ b/scripts/check_imports_and_dependencies.py @@ -26,8 +26,20 @@ import sys from collections import defaultdict from functools import wraps +from importlib.machinery import ModuleSpec from pathlib import Path -from typing import Any, Callable, Dict, Generator, List, Optional, Set, Tuple, Union +from typing import ( + Any, + Callable, + Dict, + Generator, + List, + Optional, + Set, + Tuple, + Union, + cast, +) from pip._internal.commands.show import search_packages_info # type: ignore @@ -165,8 +177,8 @@ def get_section_dependencies_from_setup(cls) -> Dict[str, Dict[str, List[Path]]] spec = importlib.util.spec_from_file_location( "setup", str(AEA_ROOT_DIR / "setup.py") ) - setup = importlib.util.module_from_spec(spec) - sys.modules[spec.name] = setup + setup = importlib.util.module_from_spec(cast(ModuleSpec, spec)) + sys.modules[cast(ModuleSpec, spec).name] = setup spec.loader.exec_module(setup) # type: ignore sections_dependencies = copy.deepcopy(setup.all_extras) # type: ignore diff --git a/setup.cfg b/setup.cfg index 23e2685a77..77b1bb9139 100644 --- a/setup.cfg +++ b/setup.cfg @@ -243,6 +243,30 @@ ignore_missing_imports = True [mypy-google.*] ignore_missing_imports = True +[mypy-click.*] +ignore_missing_imports = True + +[mypy-yaml.*] +ignore_missing_imports = True + +[mypy-requests.*] +ignore_missing_imports = True + +[mypy-certifi.*] +ignore_missing_imports = True + +[mypy-werkzeug.*] +ignore_missing_imports = True + +[mypy-pkg_resources.*] +ignore_missing_imports = True + +[mypy-gyms.*] +ignore_missing_imports = True + +[mypy-rl.*] +ignore_missing_imports = True + [darglint] docstring_style=sphinx strictness=short diff --git a/setup.py b/setup.py index c2b109c56d..f1cbd45f21 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ def get_all_extras() -> Dict: "click==8.0.2", "pyyaml>=4.2b1,<6.0", "jsonschema>=3.0.0,<4.0.0", - "packaging>=20.3,<21.0", + "packaging>=20.3,<22.0", "semver>=2.9.1,<3.0.0", ] @@ -55,7 +55,7 @@ def get_all_extras() -> Dict: "semver>=2.9.1,<3.0.0", "base58>=1.0.3,<3.0.0", "jsonschema>=3.0.0,<4.0.0", - "packaging>=20.3,<21.0", + "packaging>=20.3,<22.0", "protobuf>=3.19.0,<4.0.0", "pymultihash==0.8.2", "pyyaml>=4.2b1,<6.0", diff --git a/tox.ini b/tox.ini index c824177dd9..d6875de53c 100644 --- a/tox.ini +++ b/tox.ini @@ -216,7 +216,7 @@ commands = {toxinidir}/scripts/freeze_dependencies.py -o {envtmpdir}/requirement skipsdist = True skip_install = True deps = - mypy==0.782 + mypy==0.910 commands = mypy aea packages --disallow-untyped-defs mypy benchmark examples --check-untyped-defs mypy scripts tests