Code Monkey home page Code Monkey logo

funcsigs's People

Contributors

aliles avatar epsy avatar tripplilley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

funcsigs's Issues

ValueError: no signature found for builtin function <built-in function issubclass>

from funcsigs import signature
from functools import partial
f = partial(issubclass, bool)
signature(f)

yields

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Miniconda3\envs\tools_py2\lib\site-packages\funcsigs\__init__.py", line 108, in signature
    sig = signature(obj.func)
  File "C:\Miniconda3\envs\tools_py2\lib\site-packages\funcsigs\__init__.py", line 185, in signature
    raise ValueError(msg)
ValueError: no signature found for builtin function <built-in function issubclass>

bind(self=xxx) fails

I have a method like so:

class F:
def f(a, self):
pass

signature(partial(F.f, None)).bind(self=10)

fails, due to receiving self too many times.

The function bind() can't be defined with self as its own parameter - it conflicts with binds that pass self in. Instead it needs to take _args, *_kwargs, and pull self out of args[0].

I'll throw up a patch in alittle, for now (in mock), I'm monkeypatching to fix it.

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

Pip install broken

Currently it is not possible to install funcsigs using pip install.

The problem is caused by this line:
extras_require = {

     ':python_version<"2.7"': ['ordereddict'],
  },

error in funcsigs setup command: Invalid environment marker: python_version<"2.7"

Please remove the extra colon from the start of the string.

cython support?

Hello, my name is Joel.
I've recently opened an issue in scikit-learn, and it turns out the issue has to do with funcsigs.

My question is:
Can the signature() method in funcsigs.py be used with a cython function (cyfunction object)?
As you can see in the other issue, I'm using python 2.7

Thanks!

Backport inspect.unwrap from Python 3.4?

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.

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

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

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.

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?

signature() takes first parameter off of unbound methods

funcsigs.signature() treats unbound methods as any other method, despite m.self being None.

The attached pull requests adds a test case and fix. I've used a positional-only parameter because of this behaviour:

>>> class Test(object):
...     def method(self, *args, **kwargs):
...         return self, args, kwargs
...
>>> Test.method(Test())
(<__main__.Test object at 0x2c9fad0>, (), {})
>>> Test.method(self=Test())
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: unbound method method() must be called with Test instance as first argument
 (got nothing instead)

funcsigs 1.0 requires ordereddict, which is a python < 2.7 package

This is particularly a problem because the conda package manager won't allow you to use funcsigs 1.0 with python 2.7 because ordereddict cannot be installed for version 2.7. Setuptools fails with an error similar to this:

File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 2912, in
File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 2898, in _call_aside
File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 2925, in _initialize_master_working_set
File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 642, in _build_master
File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 943, in require
File "/home/user/miniconda3/pkgs/setuptools-20.2.2-py27_0/lib/python2.7/site-packages/setuptools-20.2.2-py2.7.egg/pkg_resources/init.py", line 830, in resolve
pkg_resources.DistributionNotFound: The 'ordereddict' distribution was not found and is required by funcsigs

Attempting to explicitly install ordereddict with the conda package manager fails like so:

-bash-4.2$ conda install ordereddict
Fetching package metadata: ....
Solving package specifications: .......
Error: Unsatisfiable package specifications.
Generating hint:
[ COMPLETE ]|################################################| 100%

Hint: the following packages conflict with each other:

  • ordereddict
  • python 2.7*

Use 'conda info ordereddict' etc. to see the dependencies for each package.

Presumably it should be possible to only require ordereddict for python versions < 2.6?

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.

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.