From bafbe9c27488ab8e018274131c4f9315bcfb2682 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Thu, 18 Jan 2024 22:14:09 +0200 Subject: [PATCH 1/4] Change return type of ion and ioff to fix unbound variable errors with Pyright --- lib/matplotlib/pyplot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 2c1403900529..a7d1bf2c0cb2 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -556,7 +556,7 @@ def isinteractive() -> bool: return matplotlib.is_interactive() -def ioff() -> ExitStack: +def ioff() -> AbstractContextManager: """ Disable interactive mode. @@ -586,7 +586,7 @@ def ioff() -> ExitStack: # ... To enable optional usage as a context manager, this function returns a - `~contextlib.ExitStack` object, which is not intended to be stored or + context manager object, which is not intended to be stored or accessed by the user. """ stack = ExitStack() @@ -596,7 +596,7 @@ def ioff() -> ExitStack: return stack -def ion() -> ExitStack: +def ion() -> AbstractContextManager: """ Enable interactive mode. @@ -626,7 +626,7 @@ def ion() -> ExitStack: # ... To enable optional usage as a context manager, this function returns a - `~contextlib.ExitStack` object, which is not intended to be stored or + context manager object, which is not intended to be stored or accessed by the user. """ stack = ExitStack() From 7a1461cbe0d51f7d6b7da61d1fcffc5ac4ed95ed Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Fri, 19 Jan 2024 00:55:34 +0200 Subject: [PATCH 2/4] Add comment explaining rationale --- lib/matplotlib/pyplot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index a7d1bf2c0cb2..a304c15ddfc8 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -556,6 +556,9 @@ def isinteractive() -> bool: return matplotlib.is_interactive() +# Note: The return type of ioff being AbstractContextManager instead of ExitStack is deliberate. +# See https://github.com/matplotlib/matplotlib/issues/27659 +# and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ioff() -> AbstractContextManager: """ Disable interactive mode. @@ -596,6 +599,9 @@ def ioff() -> AbstractContextManager: return stack +# Note: The return type of ion being AbstractContextManager instead of ExitStack is deliberate. +# See https://github.com/matplotlib/matplotlib/issues/27659 +# and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ion() -> AbstractContextManager: """ Enable interactive mode. From 2f56a2aaa8d7d7456d3f578d2136e7f2ebeaa62a Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Fri, 19 Jan 2024 01:09:33 +0200 Subject: [PATCH 3/4] Fix flake8 lint error --- lib/matplotlib/pyplot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index a304c15ddfc8..cb50a10fa8f5 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -556,7 +556,8 @@ def isinteractive() -> bool: return matplotlib.is_interactive() -# Note: The return type of ioff being AbstractContextManager instead of ExitStack is deliberate. +# Note: The return type of ioff being AbstractContextManager +# instead of ExitStack is deliberate. # See https://github.com/matplotlib/matplotlib/issues/27659 # and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ioff() -> AbstractContextManager: @@ -599,7 +600,8 @@ def ioff() -> AbstractContextManager: return stack -# Note: The return type of ion being AbstractContextManager instead of ExitStack is deliberate. +# Note: The return type of ion being AbstractContextManager +# instead of ExitStack is deliberate. # See https://github.com/matplotlib/matplotlib/issues/27659 # and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ion() -> AbstractContextManager: From f49c0e3d0bb51e9e7f613eb8967b82166e312c98 Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Fri, 19 Jan 2024 01:11:41 +0200 Subject: [PATCH 4/4] Actually fix flake8 lint --- lib/matplotlib/pyplot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index cb50a10fa8f5..d759d9ee6e5b 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -556,9 +556,9 @@ def isinteractive() -> bool: return matplotlib.is_interactive() -# Note: The return type of ioff being AbstractContextManager +# Note: The return type of ioff being AbstractContextManager # instead of ExitStack is deliberate. -# See https://github.com/matplotlib/matplotlib/issues/27659 +# See https://github.com/matplotlib/matplotlib/issues/27659 # and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ioff() -> AbstractContextManager: """ @@ -600,9 +600,9 @@ def ioff() -> AbstractContextManager: return stack -# Note: The return type of ion being AbstractContextManager +# Note: The return type of ion being AbstractContextManager # instead of ExitStack is deliberate. -# See https://github.com/matplotlib/matplotlib/issues/27659 +# See https://github.com/matplotlib/matplotlib/issues/27659 # and https://github.com/matplotlib/matplotlib/pull/27667 for more info. def ion() -> AbstractContextManager: """