Skip to content

fix: Update __exit__ method to use Optional types#733

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

fix: Update __exit__ method to use Optional types#733
AustinZhang1024 wants to merge 3 commits 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!

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.90%. Comparing base (f2904a8) to head (6a6e696).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #733   +/-   ##
=======================================
  Coverage   81.90%   81.90%           
=======================================
  Files          21       21           
  Lines        1708     1708           
  Branches      267      267           
=======================================
  Hits         1399     1399           
  Misses        230      230           
  Partials       79       79           
Flag Coverage Δ
unittests 81.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/escpos/escpos.py 75.40% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants