Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e10777

Browse files
authored
Merge pull request#20097 from anntzer/nc
Use nullcontext more as do-nothing context manager.
2 parentsaf3bfa9 +d7ea249 commit4e10777

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

‎lib/matplotlib/backend_bases.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"""
2727

2828
fromcollectionsimportnamedtuple
29-
fromcontextlibimportcontextmanager,suppress
29+
fromcontextlibimportcontextmanager,nullcontext
3030
fromenumimportEnum,IntEnum
3131
importfunctools
3232
importimportlib
@@ -2286,10 +2286,7 @@ def print_figure(
22862286
functools.partial(
22872287
print_method,orientation=orientation)
22882288
)
2289-
ctx= (renderer._draw_disabled()
2290-
ifhasattr(renderer,'_draw_disabled')
2291-
elsesuppress())
2292-
withctx:
2289+
withgetattr(renderer,"_draw_disabled",nullcontext)():
22932290
self.figure.draw(renderer)
22942291

22952292
ifbbox_inches:

‎lib/matplotlib/cbook/__init__.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,10 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
475475
returnfh
476476

477477

478-
@contextlib.contextmanager
479478
defopen_file_cm(path_or_file,mode="r",encoding=None):
480479
r"""Pass through file objects and context-manage path-likes."""
481480
fh,opened=to_filehandle(path_or_file,mode,True,encoding)
482-
ifopened:
483-
withfh:
484-
yieldfh
485-
else:
486-
yieldfh
481+
returnfhifopenedelsecontextlib.nullcontext(fh)
487482

488483

489484
defis_scalar_or_string(val):

‎lib/matplotlib/figure.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,21 +3089,16 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
30893089
.Figure.set_tight_layout
30903090
.pyplot.tight_layout
30913091
"""
3092-
3092+
fromcontextlibimportnullcontext
30933093
from .tight_layoutimport (
30943094
get_subplotspec_list,get_tight_layout_figure)
3095-
fromcontextlibimportsuppress
30963095
subplotspec_list=get_subplotspec_list(self.axes)
30973096
ifNoneinsubplotspec_list:
30983097
_api.warn_external("This figure includes Axes that are not "
30993098
"compatible with tight_layout, so results "
31003099
"might be incorrect.")
3101-
31023100
renderer=_get_renderer(self)
3103-
ctx= (renderer._draw_disabled()
3104-
ifhasattr(renderer,'_draw_disabled')
3105-
elsesuppress())
3106-
withctx:
3101+
withgetattr(renderer,"_draw_disabled",nullcontext)():
31073102
kwargs=get_tight_layout_figure(
31083103
self,self.axes,subplotspec_list,renderer,
31093104
pad=pad,h_pad=h_pad,w_pad=w_pad,rect=rect)

‎lib/matplotlib/tests/test_axes.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
fromcollectionsimportnamedtuple
2+
fromcontextlibimportnullcontext
23
importdatetime
34
fromdecimalimportDecimal
45
importio
56
fromitertoolsimportproduct
67
importplatform
78
fromtypesimportSimpleNamespace
8-
try:
9-
fromcontextlibimportnullcontext
10-
exceptImportError:
11-
fromcontextlibimportExitStackasnullcontext# Py3.6.
129

1310
importdateutil.tz
1411

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp