Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7100b39

Browse files
committed
Fix savefig extra argument warning on PyPy.
PyPy adds an additional frame for `functools.wraps`, with `_functools` as the name, which causes the code to decide we're no longer in Matplotlib code too early, and not find `print_figure`. This causes warnings about unexpected arguments.
1 parent 00c63a3 commit 7100b39

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,14 +1618,20 @@ def wrapper(*args, **kwargs):
16181618
if frame is None:
16191619
# when called in embedded context may hit frame is None.
16201620
break
1621+
# Work around sphinx-gallery not setting __name__.
1622+
frame_name = frame.f_globals.get('__name__', '')
16211623
if re.match(r'\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))',
1622-
# Work around sphinx-gallery not setting __name__.
1623-
frame.f_globals.get('__name__', '')):
1624-
if public_api.match(frame.f_code.co_name):
1625-
name = frame.f_code.co_name
1624+
frame_name):
1625+
name = frame.f_code.co_name
1626+
if public_api.match(name):
16261627
if name in ('print_figure', '_no_output_draw'):
16271628
seen_print_figure = True
16281629

1630+
elif frame_name == '_functools':
1631+
# PyPy adds an extra frame without module prefix for this
1632+
# functools wrapper, which we ignore to assume we're still in
1633+
# Matplotlib code.
1634+
continue
16291635
else:
16301636
break
16311637

0 commit comments

Comments
 (0)