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) Implement get_ofac_list_path without a loop #350

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 1 addition & 4 deletions pyinjective/ofac.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def __init__(self):

@classmethod
def get_ofac_list_path(cls):
current_directory = os.getcwd()
while os.path.basename(current_directory) != "sdk-python":
current_directory = os.path.dirname(current_directory)
return os.path.join(os.path.join(current_directory, "pyinjective"), OFAC_LIST_FILENAME)
return os.path.join(os.path.dirname(__file__), OFAC_LIST_FILENAME)
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve the changes with a suggestion for improvement

The new implementation of get_ofac_list_path is a significant improvement. It's more straightforward, likely more reliable, and aligns with the PR objective of implementing the method without a loop. Good job on simplifying this!

Consider adding a check to ensure the file exists at the specified location. This could help with debugging if the file is missing or moved. Here's a suggested improvement:

@classmethod
def get_ofac_list_path(cls):
    path = os.path.join(os.path.dirname(__file__), OFAC_LIST_FILENAME)
    if not os.path.exists(path):
        raise FileNotFoundError(f"OFAC list file not found at {path}")
    return path

This addition would make the method more robust and help catch configuration issues early.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check for existence of file whenever we want to open it. This function just produces a string with the path to the ofac.json file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelInjective, thank you for the clarification. That makes sense—since the existence of the file is checked when opening it elsewhere, there's no need to add the check in get_ofac_list_path(). The function's purpose is solely to provide the path.

(。・ω・。)


Learnings added
Learnt from: PavelInjective
PR: InjectiveLabs/sdk-python#350
File: pyinjective/ofac.py:25-25
Timestamp: 2024-09-23T19:13:38.964Z
Learning: In `pyinjective/ofac.py`, the function `get_ofac_list_path` only returns the path to the `ofac.json` file; checks for the existence of the file are performed when the file is opened elsewhere.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


@classmethod
async def download_ofac_list(cls):
Expand Down
Loading