Coder Social home page Coder Social logo

testing-cabal / funcsigs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rbtcollins/funcsigs

8.0 8.0 13.0 118 KB

Python function signatures package for Python 2.6, 2.7 and 3.3+

Home Page: http://pypi.python.org/pypi/funcsigs

License: Other

Makefile 0.82% Python 99.18%

funcsigs's People

Contributors

aliles avatar blckknght avatar elibixby avatar epsy avatar gjoseph92 avatar harlowja avatar jelmer avatar mgaitan avatar msabramo avatar rbtcollins avatar tipabu avatar tripplilley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

funcsigs's Issues

ordereddict not installed with pip 1.1

Reproducer:

  1. run a system with pip 1.1 (in my case, a Vagrant box based on debian/wheezy64)
  2. create a Python 2.6 virtual environment (virtualenv --python=python2.6 venv)
  3. activate the environment (source venv/bin/activate)
  4. follow the funcsigs's installation instructions (I did not find any, thus pip install funcsigs)
  5. import funcsigs (python -c "import funcsigs")

Actual behavior:

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

Expected behavior:

funcsigs can be imported

Affected versions:

  • funcsigs 1.0.2
  • pip 1.1
  • Python 2.6

Additional information

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.

Failures running tests directly (without coverage command)

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.

From aliles#20, filed by @jstemmer

backporting inspect.unwrap

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.

From aliles#12, filed by @ncoghlan

multiple test failures in version 0.4 with pypy3

======================================================================
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

----------------------------------------------------------------------

From aliles#18, filed by @jlec

Installation failure in virtualenv on CentOS 7.2

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"

pickle support?

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...

From aliles#19, filed by @asmodehn

Add apply_defaults method to BoundArguments (from Python 3.5)

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).

_ParameterKind breaks copy.deepcopy by using keyword only constructor

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.

pip wheel doesn't make a wheel of this package

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

symlink requires admin rights on Windows

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:

  1. Delete docs/index.rst if it's not strictly needed and just points to README.rst anyway.
  2. Replace the symlink at docs/index.rst with a file containing a short text message, telling the user to look at README.rst instead.
  3. Copy README.rst to docs/index.rst.

funcsig in python2.7 fails with wrapped functions that have more than 1 positional argument

<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?

From aliles#21, filed by @bmoscon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.