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

Improve error message when client is not yet initialised #3698

Merged

Conversation

marcuslimdw
Copy link
Contributor

User.client is only set after open is called. Since having a valid client instance is necessary to test anything, whether client is set is checked in most methods. However, this is done with a simple assert self.client, which gives an opaque AssertionError if the user has indeed forgotten to call open. This PR improves the error message to specifically call that out.

@rodja rodja self-requested a review September 9, 2024 03:30
Copy link
Member

@rodja rodja left a comment

Choose a reason for hiding this comment

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

That's great @marcuslimdw. I like showing a better error message. Unfortunately your modification breaks the mypy type checking. Maybe you can modify it to make client a property which can raise the error?

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

I quickly replaced the function with a new _client property that returns a (non-optional) Client. Now mypy is happy again.

@falkoschindler falkoschindler added this to the 2.2 milestone Sep 26, 2024
@falkoschindler falkoschindler added the enhancement New feature or request label Sep 26, 2024
@falkoschindler falkoschindler merged commit ca5a5f9 into zauberzeug:main Sep 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants