-
Notifications
You must be signed in to change notification settings - Fork 235
clib.session: Refactor to simplify the checking of currently open session #3523
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,7 +160,7 @@ def session_pointer(self) -> ctp.c_void_p: | |
| If trying to access without a currently open GMT session (i.e., outside of | ||
| the context manager). | ||
| """ | ||
| if not hasattr(self, "_session_pointer") or self._session_pointer is None: | ||
| if getattr(self, "_session_pointer", None) is None: | ||
| raise GMTCLibNoSessionError("No currently open GMT API session.") | ||
| return self._session_pointer | ||
|
|
||
|
|
@@ -338,17 +338,16 @@ def create(self, name: str): | |
| name | ||
| A name for this session. Doesn't really affect the outcome. | ||
| """ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in #3448 (comment), a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Edit: Read astral-sh/ruff#1947 again, actually it's unclear if the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted back to |
||
| # Check if there is a currently open session by accessing the "session_pointer" | ||
| # attribute. If not, it will raise the GMTCLibNoSessionError exception and we're | ||
| # free to create a new one. Otherwise, we will raise a GMTCLibError exception. | ||
| try: | ||
| # Won't raise an exception if there is a currently open session. | ||
| _ = self.session_pointer | ||
| # In this case, fail to create a new session until the old one is destroyed. | ||
| msg = ( | ||
| "Failed to create a GMT API session: There is a currently open session." | ||
| " Must destroy it first." | ||
| "Failed to create a GMT API session: " | ||
| "There is currently an open session. Must destroy it first." | ||
| ) | ||
| raise GMTCLibError(msg) | ||
| # If the exception is raised, this means that there is no open session and we're | ||
| # free to create a new one. | ||
| except GMTCLibNoSessionError: | ||
| pass | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not hasattr(self, "_session_pointer") or self._session_pointer is None:is equivalent toif getattr(self, "_session_pointer", None) is None:.