Skip to content

Commit

Permalink
fix: import issue (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 28, 2024
1 parent 01a9c9f commit cb393d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
10 changes: 1 addition & 9 deletions ape_tokens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,9 @@ def converters():
yield AddressType, TokenSymbolConverter


tokens = None # NOTE: Initialized lazily


def __getattr__(name: str) -> Any:
if name == "tokens":

global tokens
if tokens is None:
from .managers import TokenManager as _TokenManager

tokens = _TokenManager()
from .main import tokens

return tokens

Expand Down
7 changes: 7 additions & 0 deletions ape_tokens/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Separated from __init__.py so CLI module loads faster during --help.
"""

from .managers import TokenManager as _TokenManager

tokens = _TokenManager()
10 changes: 10 additions & 0 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ape_tokens import tokens


def test_tokens():
assert tokens is not None

# Show is the same
from ape_tokens import tokens as tokens2

assert id(tokens2) == id(tokens)

0 comments on commit cb393d5

Please sign in to comment.