-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11059 from pymedusa/release/release-1.0.10
Release/release 1.0.10
- Loading branch information
Showing
25 changed files
with
405 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
import types | ||
|
||
__author__ = "Benjamin Peterson <[email protected]>" | ||
__version__ = "1.15.0" | ||
__version__ = "1.16.0" | ||
|
||
|
||
# Useful for very coarse version differentiation. | ||
|
@@ -71,6 +71,11 @@ def __len__(self): | |
MAXSIZE = int((1 << 63) - 1) | ||
del X | ||
|
||
if PY34: | ||
from importlib.util import spec_from_loader | ||
else: | ||
spec_from_loader = None | ||
|
||
|
||
def _add_doc(func, doc): | ||
"""Add documentation to a function.""" | ||
|
@@ -186,6 +191,11 @@ def find_module(self, fullname, path=None): | |
return self | ||
return None | ||
|
||
def find_spec(self, fullname, path, target=None): | ||
if fullname in self.known_modules: | ||
return spec_from_loader(fullname, self) | ||
return None | ||
|
||
def __get_module(self, fullname): | ||
try: | ||
return self.known_modules[fullname] | ||
|
@@ -223,6 +233,12 @@ def get_code(self, fullname): | |
return None | ||
get_source = get_code # same as get_code | ||
|
||
def create_module(self, spec): | ||
return self.load_module(spec.name) | ||
|
||
def exec_module(self, module): | ||
pass | ||
|
||
_importer = _SixMetaPathImporter(__name__) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,38 @@ | ||
# This is a copy of the inspect.getcallargs() function from Python 2.7 | ||
# so we can provide it for use under Python 2.6. As the code in this | ||
# file derives from the Python distribution, it falls under the version | ||
# of the PSF license used for Python 2.7. | ||
# The inspect.formatargspec() function was dropped in Python 3.11 but we need | ||
# need it for when constructing signature changing decorators based on result of | ||
# inspect.getargspec() or inspect.getfullargspec(). The code here implements | ||
# inspect.formatargspec() base on Parameter and Signature from inspect module, | ||
# which were added in Python 3.6. Thanks to Cyril Jouve for the implementation. | ||
|
||
from inspect import getargspec, ismethod | ||
import sys | ||
|
||
def getcallargs(func, *positional, **named): | ||
"""Get the mapping of arguments to values. | ||
A dict is returned, with keys the function argument names (including the | ||
names of the * and ** arguments, if any), and values the respective bound | ||
values from 'positional' and 'named'.""" | ||
args, varargs, varkw, defaults = getargspec(func) | ||
f_name = func.__name__ | ||
arg2value = {} | ||
|
||
# The following closures are basically because of tuple parameter unpacking. | ||
assigned_tuple_params = [] | ||
def assign(arg, value): | ||
if isinstance(arg, str): | ||
arg2value[arg] = value | ||
else: | ||
assigned_tuple_params.append(arg) | ||
value = iter(value) | ||
for i, subarg in enumerate(arg): | ||
try: | ||
subvalue = next(value) | ||
except StopIteration: | ||
raise ValueError('need more than %d %s to unpack' % | ||
(i, 'values' if i > 1 else 'value')) | ||
assign(subarg, subvalue) | ||
try: | ||
next(value) | ||
except StopIteration: | ||
pass | ||
else: | ||
raise ValueError('too many values to unpack') | ||
def is_assigned(arg): | ||
if isinstance(arg, str): | ||
return arg in arg2value | ||
return arg in assigned_tuple_params | ||
if ismethod(func) and func.im_self is not None: | ||
# implicit 'self' (or 'cls' for classmethods) argument | ||
positional = (func.im_self,) + positional | ||
num_pos = len(positional) | ||
num_total = num_pos + len(named) | ||
num_args = len(args) | ||
num_defaults = len(defaults) if defaults else 0 | ||
for arg, value in zip(args, positional): | ||
assign(arg, value) | ||
if varargs: | ||
if num_pos > num_args: | ||
assign(varargs, positional[-(num_pos-num_args):]) | ||
else: | ||
assign(varargs, ()) | ||
elif 0 < num_args < num_pos: | ||
raise TypeError('%s() takes %s %d %s (%d given)' % ( | ||
f_name, 'at most' if defaults else 'exactly', num_args, | ||
'arguments' if num_args > 1 else 'argument', num_total)) | ||
elif num_args == 0 and num_total: | ||
try: | ||
from inspect import Parameter, Signature | ||
except ImportError: | ||
from inspect import formatargspec | ||
else: | ||
def formatargspec(args, varargs=None, varkw=None, defaults=None, | ||
kwonlyargs=(), kwonlydefaults={}, annotations={}): | ||
if kwonlydefaults is None: | ||
kwonlydefaults = {} | ||
ndefaults = len(defaults) if defaults else 0 | ||
parameters = [ | ||
Parameter( | ||
arg, | ||
Parameter.POSITIONAL_OR_KEYWORD, | ||
default=defaults[i] if i >= 0 else Parameter.empty, | ||
annotation=annotations.get(arg, Parameter.empty), | ||
) for i, arg in enumerate(args, ndefaults - len(args)) | ||
] | ||
if varargs: | ||
parameters.append(Parameter(varargs, Parameter.VAR_POSITIONAL)) | ||
parameters.extend( | ||
Parameter( | ||
kwonlyarg, | ||
Parameter.KEYWORD_ONLY, | ||
default=kwonlydefaults.get(kwonlyarg, Parameter.empty), | ||
annotation=annotations.get(kwonlyarg, Parameter.empty), | ||
) for kwonlyarg in kwonlyargs | ||
) | ||
if varkw: | ||
if num_pos: | ||
# XXX: We should use num_pos, but Python also uses num_total: | ||
raise TypeError('%s() takes exactly 0 arguments ' | ||
'(%d given)' % (f_name, num_total)) | ||
else: | ||
raise TypeError('%s() takes no arguments (%d given)' % | ||
(f_name, num_total)) | ||
for arg in args: | ||
if isinstance(arg, str) and arg in named: | ||
if is_assigned(arg): | ||
raise TypeError("%s() got multiple values for keyword " | ||
"argument '%s'" % (f_name, arg)) | ||
else: | ||
assign(arg, named.pop(arg)) | ||
if defaults: # fill in any missing values with the defaults | ||
for arg, value in zip(args[-num_defaults:], defaults): | ||
if not is_assigned(arg): | ||
assign(arg, value) | ||
if varkw: | ||
assign(varkw, named) | ||
elif named: | ||
unexpected = next(iter(named)) | ||
if isinstance(unexpected, unicode): | ||
unexpected = unexpected.encode(sys.getdefaultencoding(), 'replace') | ||
raise TypeError("%s() got an unexpected keyword argument '%s'" % | ||
(f_name, unexpected)) | ||
unassigned = num_args - len([arg for arg in args if is_assigned(arg)]) | ||
if unassigned: | ||
num_required = num_args - num_defaults | ||
raise TypeError('%s() takes %s %d %s (%d given)' % ( | ||
f_name, 'at least' if defaults else 'exactly', num_required, | ||
'arguments' if num_required > 1 else 'argument', num_total)) | ||
return arg2value | ||
parameters.append(Parameter(varkw, Parameter.VAR_KEYWORD)) | ||
return_annotation = annotations.get('return', Signature.empty) | ||
return str(Signature(parameters, return_annotation=return_annotation)) |
Oops, something went wrong.