testing-cabal / funcsigs Goto Github PK
View Code? Open in Web Editor NEWThis project forked from rbtcollins/funcsigs
Python function signatures package for Python 2.6, 2.7 and 3.3+
Home Page: http://pypi.python.org/pypi/funcsigs
License: Other
This project forked from rbtcollins/funcsigs
Python function signatures package for Python 2.6, 2.7 and 3.3+
Home Page: http://pypi.python.org/pypi/funcsigs
License: Other
virtualenv --python=python2.6 venv
)source venv/bin/activate
)pip install funcsigs
)python -c "import funcsigs"
)An ImportError
with the following traceback:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/vagrant/venv/lib/python2.6/site-packages/funcsigs/__init__.py", line 16, in <module>
from ordereddict import OrderedDict
ImportError: No module named ordereddict
funcsigs can be imported
If I upgrade pip (to 8.1.2), everything seems to work. Thus I guess that funcsigs has to express the dependency on a newer pip. I am not sure whether it might be achieved by setup_requires
like you did before. If not, at least a note in installation instructions (which has to be propagated to mock and others) would be nice.
Please note that upgrading setuptools (to 28.6.0) (even before issuing the installation of funcsigs) was not enough in my case.
Trying to run the tests directly (without using the coverage command) currently fails because unittest.begin() is not a valid method. This should be replaced with with unittest.main().
Fixing this (and running tests standalone) will break one of the formatannotation tests, as the expected result depends on how the tests are run.
http://bugs.python.org/issue23764 highlighted that one of the useful features inspect.signature offers over the old APIs is correctly following wrapper chains.
Python 3.4 split that feature out into an independently usable component: https://docs.python.org/3/library/inspect.html#inspect.unwrap
There are some other features potentially worth backporting from 3.4 (like the inspect.signature based inspect.getargspec and inspect.getfullargspec), so a full rebase may even be worthwhile.
======================================================================
ERROR: test_signature_on_callable_objects (tests.test_inspect.TestSignatureObject)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/var/tmp/portage/dev-python/funcsigs-0.4/work/funcsigs-0.4/tests/test_inspect.py", line 508, in test_signature_on_callable_objects
self.assertEqual(self.signature(Foo()),
File "/var/tmp/portage/dev-python/funcsigs-0.4/work/funcsigs-0.4/tests/test_inspect.py", line 17, in signature
sig = inspect.signature(func)
File "/var/tmp/portage/dev-python/funcsigs-0.4/work/funcsigs-0.4/funcsigs/__init__.py", line 176, in signature
raise ValueError('callable {0!r} is not supported by signature'.format(obj))
ValueError: callable <tests.test_inspect.Foo object at 0x0000000001405948> is not supported by signature
======================================================================
ERROR: test_signature_on_class (tests.test_inspect.TestSignatureObject)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<string>", line 7, in test_signature_on_class
File "/var/tmp/portage/dev-python/funcsigs-0.4/work/funcsigs-0.4/tests/test_inspect.py", line 17, in signature
sig = inspect.signature(func)
File "/var/tmp/portage/dev-python/funcsigs-0.4/work/funcsigs-0.4/funcsigs/__init__.py", line 176, in signature
raise ValueError('callable {0!r} is not supported by signature'.format(obj))
ValueError: callable <class 'tests.test_inspect.C'> is not supported by signature
----------------------------------------------------------------------
I'm trying to install Elasticluster in a virtualenv on CentOS 7.2.
funcsigs
is one of the dependencies. However, when I run python setup.py install
, there is an error with funcsigs
:
Processing dependencies for elasticluster==1.2.1.rc1
Searching for funcsigs>=0.4
Reading https://pypi.python.org/simple/funcsigs/
Best match: funcsigs 1.0.1
Downloading https://pypi.python.org/packages/ab/5b/a6dff630fe5b68a4d2a049b6d95b51ad1510fb72e9606d656feb2c34efd8/funcsigs-1.0.1.tar.gz#md5=c2d84de116ce1aba0dc844a359cd20dd
Processing funcsigs-1.0.1.tar.gz
Writing /tmp/easy_install-hpmqdV/funcsigs-1.0.1/setup.cfg
Running funcsigs-1.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hpmqdV/funcsigs-1.0.1/egg-dist-tmp-60yD2x
error: Setup script exited with error in funcsigs setup command: Invalid environment marker: python_version<"2.7"
If you see the API for inspect.signature, you will see it supports a follow_unwrapped argument. This backport does not provide the option of following the wrap chain or not. https://docs.python.org/3/library/inspect.html#inspect.signature
Basically trying to pickle a signature pickle.dumps(signature(my_func))
leads to :
File "/usr/lib/python2.7/pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 77, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled
It would be useful to be able to serialize function signatures. Although I don't know what python 3.X does about this and if this is in the scope of funcsigs to implement this...
The changelog's most recent entry is for 0.5.0, which was never released:
https://github.com/testing-cabal/funcsigs/blob/master/CHANGELOG
The 1.x versions are missing:
0.4...1.0.0
1.0.0...1.0.1
1.0.1...1.0.2
Python 3.5 extended the inspect.BoundArguments
class, adding a new apply_defaults
method which updates arguments
with default values for any parameters that haven't been bound yet.
See Python issue 24190 for the discussion and the patch implementing the change (including doc changes and tests). I've not tried it myself, but I suspect that patch should almost work for this backported version of the code as well. The additions to the main library code should be fine. The test code however might need to be simplified a tiny bit to avoid using features that don't exist in older Python versions (e.g. annotations).
The setup.py
now inconditionally specifies a dependency on ordereddict
, while it's only necessary for Python 2.6 and earlier.
The "homepage" link at the bottom of https://pypi.python.org/pypi/funcsigs points to http://funcsigs.readthedocs.org/ which is out of date (still uses https://github.com/aliles/funcsigs).
Also, the README contains references to both the old repo/build status, plus the out of date read the docs page:
https://github.com/testing-cabal/funcsigs/blame/1b88d78a3883463c2d261173b959c41c9b2f3435/README.rst#L334-L351
copy.deepcopy's default reconstructor passes only positional arguments to new object constructors.
Since _ParameterKind directly looks up the "name" argument in the keyword dictionary (which is empty), any attempt to deepcopy a Parameter, BoundArguments, or Signature object will raise a KeyError.
Hello :)
I'm using Sentry which uses Mock which uses this package.
I used to run pip wheel -r requirements.txt and then pip install --no-index --use-wheel --find-links=WHEEL_DIR -r requirements.txt and it worked fine for older versions. But now that this package emerged as a dependency, it no longer works.
I deleted the --no-index flag and the installation works for now. Would be good to skip the index though.
From aliles#16, filed by @vassilevsky
The repo contains a symlink (docs/index.rst -> ../README.rst), which has the effect that unpacking funcsigs
on Windows requires admin rights.
Admin rights are required due to Windows not generally allowing (temporarily) dangling symlinks, as explained e.g. in this thread.
The reason why this matters is that distributing funcsigs
as a packed bundle is common for systems depending on funcsigs
, such as GoogleCloudPlatform/gsutil.
gsutil
in turn is used in projects like Chrome and Dart.
Example issue: dart-lang/sdk#41729
I see a few ways to address this issue:
docs/index.rst
if it's not strictly needed and just points to README.rst
anyway.docs/index.rst
with a file containing a short text message, telling the user to look at README.rst
instead.README.rst
to docs/index.rst
.<funcsigs.Signature object at 0x7fcc113c7dd0>, args = ('hello',), kwargs = {}, partial = False
def _bind(self, args, kwargs, partial=False):
'''Private method. Don't use directly.'''
arguments = OrderedDict()
parameters = iter(self.parameters.values())
parameters_ex = ()
arg_vals = iter(args)
if partial:
# Support for binding arguments to 'functools.partial' objects.
# See 'functools.partial' case in 'signature()' implementation
# for details.
for param_name, param in self.parameters.items():
if (param._partial_kwarg and param_name not in kwargs):
# Simulating 'functools.partial' behavior
kwargs[param_name] = param.default
while True:
# Let's iterate through the positional arguments and corresponding
# parameters
try:
arg_val = next(arg_vals)
except StopIteration:
# No more positional arguments
try:
param = next(parameters)
except StopIteration:
# No more parameters. That's it. Just need to check that
# we have no `kwargs` after this while loop
break
else:
if param.kind == _VAR_POSITIONAL:
# That's OK, just empty *args. Let's start parsing
# kwargs
break
elif param.name in kwargs:
if param.kind == _POSITIONAL_ONLY:
msg = '{arg!r} parameter is positional only, ' \
'but was passed as a keyword'
msg = msg.format(arg=param.name)
raise TypeError(msg)
parameters_ex = (param,)
break
elif (param.kind == _VAR_KEYWORD or
param.default is not _empty):
# That's fine too - we have a default value for this
# parameter. So, lets start parsing `kwargs`, starting
# with the current parameter
parameters_ex = (param,)
break
else:
if partial:
parameters_ex = (param,)
break
else:
msg = '{arg!r} parameter lacking default value'
msg = msg.format(arg=param.name)
raise TypeError(msg)
else:
# We have a positional argument to process
try:
param = next(parameters)
except StopIteration:
raise TypeError('too many positional arguments')
else:
if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
# Looks like we have no parameter for this positional
# argument
> raise TypeError('too many positional arguments')
E TypeError: too many positional arguments
changing the positional arguments to keyword arguments resolves this issue, but surely funcsigs should work with multiple positional arguments?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.