125
125
import functools
126
126
import io
127
127
import inspect
128
+ from inspect import Parameter
128
129
import itertools
129
130
import locale
130
131
import logging
174
175
}"""
175
176
176
177
177
- _python27 = (sys .version_info .major == 2 and sys .version_info .minor >= 7 )
178
- _python34 = (sys .version_info .major == 3 and sys .version_info .minor >= 4 )
179
- if not (_python27 or _python34 ):
180
- raise ImportError ("Matplotlib requires Python 2.7 or 3.4 or later" )
181
-
182
- if _python27 :
183
- _log .addHandler (logging .NullHandler ())
184
-
185
-
186
178
def compare_versions (a , b ):
187
179
"return True if a is greater than or equal to b"
180
+ if isinstance (a , bytes ):
181
+ cbook .warn_deprecated (
182
+ "3.0" , "compare_version arguments should be strs." )
183
+ a = a .decode ('ascii' )
184
+ if isinstance (b , bytes ):
185
+ cbook .warn_deprecated (
186
+ "3.0" , "compare_version arguments should be strs." )
187
+ b = b .decode ('ascii' )
188
188
if a :
189
- if six .PY3 :
190
- if isinstance (a , bytes ):
191
- a = a .decode ('ascii' )
192
- if isinstance (b , bytes ):
193
- b = b .decode ('ascii' )
194
189
a = distutils .version .LooseVersion (a )
195
190
b = distutils .version .LooseVersion (b )
196
191
return a >= b
@@ -750,10 +745,6 @@ def get_py2exe_datafiles():
750
745
_ , tail = os .path .split (datapath )
751
746
d = {}
752
747
for root , _ , files in os .walk (datapath ):
753
- # Need to explicitly remove cocoa_agg files or py2exe complains
754
- # NOTE I don't know why, but do as previous version
755
- if 'Matplotlib.nib' in files :
756
- files .remove ('Matplotlib.nib' )
757
748
files = [os .path .join (root , filename ) for filename in files ]
758
749
root = root .replace (tail , 'mpl-data' )
759
750
root = root [root .index ('mpl-data' ):]
@@ -1602,52 +1593,24 @@ def foo(ax, *args, **kwargs)
1602
1593
replace_names = set (replace_names )
1603
1594
1604
1595
def param (func ):
1605
- new_sig = None
1606
- # signature is since 3.3 and wrapped since 3.2, but we support 3.4+.
1607
- python_has_signature = python_has_wrapped = six .PY3
1608
-
1609
- # if in a legacy version of python and IPython is already imported
1610
- # try to use their back-ported signature
1611
- if not python_has_signature and 'IPython' in sys .modules :
1612
- try :
1613
- import IPython .utils .signatures
1614
- signature = IPython .utils .signatures .signature
1615
- Parameter = IPython .utils .signatures .Parameter
1616
- except ImportError :
1617
- pass
1596
+ sig = inspect .signature (func )
1597
+ _has_varargs = False
1598
+ _has_varkwargs = False
1599
+ _arg_names = []
1600
+ params = list (sig .parameters .values ())
1601
+ for p in params :
1602
+ if p .kind is Parameter .VAR_POSITIONAL :
1603
+ _has_varargs = True
1604
+ elif p .kind is Parameter .VAR_KEYWORD :
1605
+ _has_varkwargs = True
1618
1606
else :
1619
- python_has_signature = True
1620
- else :
1621
- if python_has_signature :
1622
- signature = inspect .signature
1623
- Parameter = inspect .Parameter
1624
-
1625
- if not python_has_signature :
1626
- arg_spec = inspect .getargspec (func )
1627
- _arg_names = arg_spec .args
1628
- _has_varargs = arg_spec .varargs is not None
1629
- _has_varkwargs = arg_spec .keywords is not None
1607
+ _arg_names .append (p .name )
1608
+ data_param = Parameter ('data' , Parameter .KEYWORD_ONLY , default = None )
1609
+ if _has_varkwargs :
1610
+ params .insert (- 1 , data_param )
1630
1611
else :
1631
- sig = signature (func )
1632
- _has_varargs = False
1633
- _has_varkwargs = False
1634
- _arg_names = []
1635
- params = list (sig .parameters .values ())
1636
- for p in params :
1637
- if p .kind is Parameter .VAR_POSITIONAL :
1638
- _has_varargs = True
1639
- elif p .kind is Parameter .VAR_KEYWORD :
1640
- _has_varkwargs = True
1641
- else :
1642
- _arg_names .append (p .name )
1643
- data_param = Parameter ('data' ,
1644
- Parameter .KEYWORD_ONLY ,
1645
- default = None )
1646
- if _has_varkwargs :
1647
- params .insert (- 1 , data_param )
1648
- else :
1649
- params .append (data_param )
1650
- new_sig = sig .replace (parameters = params )
1612
+ params .append (data_param )
1613
+ new_sig = sig .replace (parameters = params )
1651
1614
# Import-time check: do we have enough information to replace *args?
1652
1615
arg_names_at_runtime = False
1653
1616
# there can't be any positional arguments behind *args and no
@@ -1701,7 +1664,7 @@ def param(func):
1701
1664
label_namer_pos = 9999 # bigger than all "possible" argument lists
1702
1665
if (label_namer and # we actually want a label here ...
1703
1666
arg_names and # and we can determine a label in *args ...
1704
- ( label_namer in arg_names ) ): # and it is in *args
1667
+ label_namer in arg_names ): # and it is in *args
1705
1668
label_namer_pos = arg_names .index (label_namer )
1706
1669
if "label" in arg_names :
1707
1670
label_pos = arg_names .index ("label" )
@@ -1789,10 +1752,10 @@ def inner(ax, *args, **kwargs):
1789
1752
# didn't set one. Note: if the user puts in "label=None", it does
1790
1753
# *NOT* get replaced!
1791
1754
user_supplied_label = (
1792
- ( len (args ) >= _label_pos ) or # label is included in args
1793
- ( 'label' in kwargs ) # ... or in kwargs
1755
+ len (args ) >= _label_pos or # label is included in args
1756
+ 'label' in kwargs # ... or in kwargs
1794
1757
)
1795
- if ( label_namer and not user_supplied_label ) :
1758
+ if label_namer and not user_supplied_label :
1796
1759
if _label_namer_pos < len (args ):
1797
1760
kwargs ['label' ] = get_label (args [_label_namer_pos ], label )
1798
1761
elif label_namer in kwargs :
@@ -1808,10 +1771,7 @@ def inner(ax, *args, **kwargs):
1808
1771
1809
1772
inner .__doc__ = _add_data_doc (inner .__doc__ ,
1810
1773
replace_names , replace_all_args )
1811
- if not python_has_wrapped :
1812
- inner .__wrapped__ = func
1813
- if new_sig is not None :
1814
- inner .__signature__ = new_sig
1774
+ inner .__signature__ = new_sig
1815
1775
return inner
1816
1776
1817
1777
return param
0 commit comments