-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
@@ -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: |
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 to if getattr(self, "_session_pointer", None) is None:
.
@@ -338,19 +338,12 @@ def create(self, name: str): | |||
name | |||
A name for this session. Doesn't really affect the outcome. | |||
""" |
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 self.session_pointer
is defined and is not None, then we know we have an open session. The try..except
statement was added in 2018 (#210) and is not necessary.
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.
As mentioned in #3448 (comment), a with contextlib.supress
block should ideally be used when there is only one line below it. I feel like we should keep the previous try-except block.
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.
It's impossible that the msg
assignment and the raise GMTCLibError
lines can raise a GMTCLibNoSessionError
exception, so we should be safe.
Edit: Read astral-sh/ruff#1947 again, actually it's unclear if the raise GMTCLibError
statement will be executed or not. I think we have to go back to try..except
.
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.
Reverted back to try..except
in da9c5e1 and improve the comments to make it easier to understand.
b960654
to
42ae467
Compare
42ae467
to
3d0c91b
Compare
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
Just some refactoring to simplify the codes. See the changes for more details.