Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tokens was None on import bug #48

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)