Skip to content

Commit 1ec197c

Browse files
authored
fix: use getattr for EthereumProvider network configs instead of dictionary key lookup (#128)
I am inheriting from NetworkConfig for Hardhat, but the behavior of key lookup vs. attribute lookup is different for the base class vs. inherited class. Base NetworkConfig class: (Pdb) self.config NetworkConfig(ethereum={'development': {'uri': 'http://localhost:8555'}}) (Pdb) self.config['ethereum'] {'development': {'uri': 'http://localhost:8555'}} (Pdb) getattr(self.config, 'ethereum') {'development': {'uri': 'http://localhost:8555'}} Vs. my inherited class where the key lookup fails: (Pdb) self.config HardhatNetworkConfig(ethereum={'development': {'uri': 'http://localhost:8555'}}, fork_url=None, fork_block_number=None, port=8555) (Pdb) self.config['ethereum'] *** KeyError: "''ethereum'" (Pdb) self.config.ethereum {'development': {'uri': 'http://localhost:8555'}} Since attribute lookup works on both classes, let's just use that. Also fixed a typo in the KeyError raised by the ConfigItem class.
1 parent aec5e50 commit 1ec197c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/ape/api/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __getitem__(self, attrname: str) -> Any:
3535
if attrname in self.__slots__:
3636
return getattr(self, attrname)
3737

38-
raise KeyError(f"''{attrname}'")
38+
raise KeyError(f"{attrname!r}")
3939

4040

4141
class ConfigDict(ConfigItem):

src/ape_http/providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class EthereumProvider(ProviderAPI):
3030

3131
@property
3232
def uri(self) -> str:
33-
return self.config[self.network.ecosystem.name][self.network.name]["uri"]
33+
return getattr(self.config, self.network.ecosystem.name)[self.network.name]["uri"]
3434

3535
def connect(self):
3636
self._web3 = Web3(HTTPProvider(self.uri))

0 commit comments

Comments
 (0)