Skip to content

Commit b6f7a68

Browse files
authored
Merge pull request matplotlib#27667 from FeldrinH/ion-ioff-typing
Change return type of `ion` and `ioff` to fix unbound variable errors with Pyright
2 parents 88d64e5 + f49c0e3 commit b6f7a68

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/matplotlib/pyplot.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,11 @@ def isinteractive() -> bool:
554554
return matplotlib.is_interactive()
555555

556556

557-
def ioff() -> ExitStack:
557+
# Note: The return type of ioff being AbstractContextManager
558+
# instead of ExitStack is deliberate.
559+
# See https://github.com/matplotlib/matplotlib/issues/27659
560+
# and https://github.com/matplotlib/matplotlib/pull/27667 for more info.
561+
def ioff() -> AbstractContextManager:
558562
"""
559563
Disable interactive mode.
560564
@@ -584,7 +588,7 @@ def ioff() -> ExitStack:
584588
# ...
585589
586590
To enable optional usage as a context manager, this function returns a
587-
`~contextlib.ExitStack` object, which is not intended to be stored or
591+
context manager object, which is not intended to be stored or
588592
accessed by the user.
589593
"""
590594
stack = ExitStack()
@@ -594,7 +598,11 @@ def ioff() -> ExitStack:
594598
return stack
595599

596600

597-
def ion() -> ExitStack:
601+
# Note: The return type of ion being AbstractContextManager
602+
# instead of ExitStack is deliberate.
603+
# See https://github.com/matplotlib/matplotlib/issues/27659
604+
# and https://github.com/matplotlib/matplotlib/pull/27667 for more info.
605+
def ion() -> AbstractContextManager:
598606
"""
599607
Enable interactive mode.
600608
@@ -624,7 +632,7 @@ def ion() -> ExitStack:
624632
# ...
625633
626634
To enable optional usage as a context manager, this function returns a
627-
`~contextlib.ExitStack` object, which is not intended to be stored or
635+
context manager object, which is not intended to be stored or
628636
accessed by the user.
629637
"""
630638
stack = ExitStack()

0 commit comments

Comments
 (0)