Skip to content

fix: Update __exit__ method to use Optional types#733

Open
AustinZhang1024 wants to merge 1 commit into
python-escpos:masterfrom
AustinZhang1024:patch-1
Open

fix: Update __exit__ method to use Optional types#733
AustinZhang1024 wants to merge 1 commit into
python-escpos:masterfrom
AustinZhang1024:patch-1

Conversation

@AustinZhang1024

Copy link
Copy Markdown

Description

From the newest document, better to allow None in the type hint.

This will fix the invalid-context-manager error of ty.

If the context was exited without an exception, all three arguments will be None.

Tested with

Windows 11

@belono belono left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @AustinZhang1024 !

From contextmanager.__exit__(exc_type, exc_val, exc_tb)

If an exception occurred while executing the body of the with statement, the arguments contain the exception type, value and traceback information. Otherwise, all three arguments are None.

You are right, if no exception is raised when exiting a context manager then all three arguments will be None, so their types should be Optional.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants