Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 695cc55

Browse files
committed
Simplified initialization
1 parent a3e2902 commit 695cc55

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

etherscan/etherscan.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import json
2+
from importlib import resources
23

34
import requests
45

56
import etherscan
7+
from etherscan import configs
68
from etherscan.enums.fields_enum import FieldsEnum as fields
79
from etherscan.utils.parsing import ResponseParser as parser
810

911

1012
class Etherscan:
13+
def __new__(cls, api_key: str):
14+
with resources.path(configs, "stable.json") as path:
15+
config_path = str(path)
16+
return cls.from_config(api_key=api_key, config_path=config_path)
17+
1118
@staticmethod
1219
def __load_config(config_path: str) -> dict:
1320
with open(config_path, "r") as f:
1421
return json.load(f)
1522

1623
@staticmethod
17-
def __run(func, api_key):
24+
def __run(func, api_key: str):
1825
def wrapper(*args, **kwargs):
1926
url = (
2027
f"{fields.PREFIX}"
@@ -28,7 +35,7 @@ def wrapper(*args, **kwargs):
2835
return wrapper
2936

3037
@classmethod
31-
def from_config(cls, config_path: str, api_key: str):
38+
def from_config(cls, api_key: str, config_path: str):
3239
config = cls.__load_config(config_path)
3340
for func, v in config.items():
3441
if not func.startswith("_"): # disabled if _

0 commit comments

Comments
 (0)