Skip to content

Commit

Permalink
fix: replace mess with setdefault
Browse files Browse the repository at this point in the history
  • Loading branch information
matnad committed Jun 1, 2020
1 parent 85c7767 commit ea7b90e
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,13 @@ def _add_to_deployment_map(self, contract: ProjectContract) -> None:

chainid = CONFIG.active_network["chainid"] if CONFIG.network_type == "live" else "dev"
deployment_map = self._load_deployment_map()

if chainid in deployment_map:
if contract._name in deployment_map[chainid] and isinstance(
deployment_map[chainid][contract._name], list
):
if contract.address in deployment_map[chainid][contract._name]:
deployment_map[chainid][contract._name].remove(contract.address)
deployment_map[chainid][contract._name].insert(0, contract.address)
else:
deployment_map[chainid][contract._name] = [contract.address]
else:
deployment_map[chainid] = {contract._name: [contract.address]}

try:
deployment_map[chainid][contract._name].remove(contract.address)
except (ValueError, KeyError):
pass
deployment_map.setdefault(chainid, {}).setdefault(contract._name, []).insert(
0, contract.address
)
self._save_deployment_map(deployment_map)

def _update_and_register(self, dict_: Any) -> None:
Expand Down

0 comments on commit ea7b90e

Please sign in to comment.