From fd38225af3b4ae7b15e477aaac1763a88b262329 Mon Sep 17 00:00:00 2001 From: antazoey Date: Wed, 8 May 2024 10:26:53 -0600 Subject: [PATCH] chore: delete double-y implemented `__getitem__` from `NetworkManager` (#2071) --- src/ape/managers/networks.py | 29 ++++-------------------- tests/functional/test_network_manager.py | 6 +++++ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/ape/managers/networks.py b/src/ape/managers/networks.py index cf15cdbad7..9ba0a57b70 100644 --- a/src/ape/managers/networks.py +++ b/src/ape/managers/networks.py @@ -172,26 +172,26 @@ def ecosystems(self) -> Dict[str, EcosystemAPI]: """ All the registered ecosystems in ``ape``, such as ``ethereum``. """ - ecosystem_objs = self._plugin_ecosystems + plugin_ecosystems = self._plugin_ecosystems # Load config. custom_networks: List = self.config_manager.get_config("networks").get("custom", []) for custom_network in custom_networks: ecosystem_name = custom_network.ecosystem - if ecosystem_name in ecosystem_objs: + if ecosystem_name in plugin_ecosystems: # Already included in previous network. continue base_ecosystem_name = ( custom_network.get("base_ecosystem_plugin") or self.default_ecosystem_name ) - existing_cls = ecosystem_objs[base_ecosystem_name] + existing_cls = plugin_ecosystems[base_ecosystem_name] ecosystem_cls = existing_cls.model_copy( update={"name": ecosystem_name}, cache_clear=("_networks_from_plugins",) ) - ecosystem_objs[ecosystem_name] = ecosystem_cls + plugin_ecosystems[ecosystem_name] = ecosystem_cls - return ecosystem_objs + return plugin_ecosystems @cached_property def _plugin_ecosystems(self) -> Dict[str, EcosystemAPI]: @@ -273,25 +273,6 @@ def __iter__(self) -> Iterator[str]: """ yield from self.ecosystems - def __getitem__(self, ecosystem_name: str) -> EcosystemAPI: - """ - Get an ecosystem by name. - - Raises: - :class:`~ape.exceptions.NetworkError`: When the given ecosystem name is - unknown. - - Args: - ecosystem_name (str): The name of the ecosystem to get. - - Returns: - :class:`~ape.api.networks.EcosystemAPI` - """ - if ecosystem_name not in self.ecosystems: - raise IndexError(f"Unknown ecosystem '{ecosystem_name}'.") - - return self.ecosystems[ecosystem_name] - def __ape_extra_attributes__(self) -> Iterator[ExtraModelAttributes]: yield ExtraModelAttributes( name="ecosystems", diff --git a/tests/functional/test_network_manager.py b/tests/functional/test_network_manager.py index 022d7016b6..382c976176 100644 --- a/tests/functional/test_network_manager.py +++ b/tests/functional/test_network_manager.py @@ -385,3 +385,9 @@ def test_fork_past_genesis(networks, mock_sepolia, mock_fork_provider, eth_teste with pytest.raises(NetworkError, match="Unable to fork past genesis block."): with networks.fork(block_number=block_id): pass + + +def test_getitem(networks): + ethereum = networks["ethereum"] + assert ethereum.name == "ethereum" + assert isinstance(ethereum, EcosystemAPI)