Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Oct 16, 2024

Just some refactoring to simplify the codes. See the changes for more details.

@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. labels Oct 16, 2024
@seisman seisman added this to the 0.14.0 milestone Oct 16, 2024
the context manager).
"""
if not hasattr(self, "_session_pointer") or self._session_pointer is None:
if getattr(self, "_session_pointer", None) is None:
Copy link
Member Author

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:.

----------
name
A name for this session. Doesn't really affect the outcome.
"""
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@seisman seisman Oct 16, 2024

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.

Copy link
Member Author

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.

@seisman seisman removed the needs review This PR has higher priority and needs review. label Oct 16, 2024
@seisman seisman marked this pull request as draft October 16, 2024 04:41
@seisman seisman force-pushed the refactor/session-pointer branch from b960654 to 42ae467 Compare October 16, 2024 04:49
@seisman seisman force-pushed the refactor/session-pointer branch from 42ae467 to 3d0c91b Compare October 16, 2024 04:54
@seisman seisman marked this pull request as ready for review October 16, 2024 04:54
@seisman seisman added the needs review This PR has higher priority and needs review. label Oct 16, 2024
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Oct 16, 2024
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Oct 16, 2024
@seisman seisman merged commit c0ad049 into main Oct 16, 2024
@seisman seisman deleted the refactor/session-pointer branch October 16, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants