mindflayer / python-mocket

a socket mock framework - for all kinds of socket animals, web-clients included
BSD 3-Clause "New" or "Revised" License
280 stars 42 forks source link

Support decorator>=5.0 #154

Closed mweinelt closed 3 years ago

mweinelt commented 3 years ago

Describe the bug As a distro we have to update our package set continuously and as such we noticed mocket pins decorator<5.

Opening up the version constraint we are seeing a single test failure:

__________________________________ test_patch __________________________________

args = (), kw = {}

    def fun(*args, **kw):
        if not kwsyntax:
>           args, kw = fix(args, kw, sig)

/nix/store/yx953vz3zzf7g8khilj09a3y958ghm1x-python3.9-decorator-5.0.9/lib/python3.9/site-packages/decorator.py:231:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/nix/store/yx953vz3zzf7g8khilj09a3y958ghm1x-python3.9-decorator-5.0.9/lib/python3.9/site-packages/decorator.py:203: in fix
    ba = sig.bind(*args, **kwargs)
/nix/store/lzf2sy1cvn4i7vkxigp9cq9qfp98g8b3-python3-3.9.6/lib/python3.9/inspect.py:3062: in bind
    return self._bind(args, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Signature (method_patch)>, args = (), kwargs = {}

    def _bind(self, args, kwargs, *, partial=False):
        """Private method. Don't use directly."""

        arguments = {}

        parameters = iter(self.parameters.values())
        parameters_ex = ()
        arg_vals = iter(args)

        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) from None
                        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:
                        # No default, not VAR_KEYWORD, not VAR_POSITIONAL,
                        # not in `kwargs`
                        if partial:
                            parameters_ex = (param,)
                            break
                        else:
                            msg = 'missing a required argument: {arg!r}'
                            msg = msg.format(arg=param.name)
>                           raise TypeError(msg) from None
E                           TypeError: missing a required argument: 'method_patch'

/nix/store/lzf2sy1cvn4i7vkxigp9cq9qfp98g8b3-python3-3.9.6/lib/python3.9/inspect.py:2977: TypeError

To Reproduce Steps to reproduce the behavior:

  1. Remove upper bound on decorator constraint
  2. python setup.py install

Expected behavior Support recent decorator releases.

Additional context n/a

mindflayer commented 3 years ago

Hi @mweinelt, I already have a branch where I am trying to fix it, but at the moment the decorator is still not decorating "async def" functions and I am not sure why. I am on it. :)

mindflayer commented 3 years ago

EDIT: it looks like the requirements.txt shipped by that version was still excluding new decorator releases. Let me check what happened and issue a new one.

mindflayer commented 3 years ago

Here is the good one, sorry for the mistake: https://pypi.org/project/mocket/3.9.44/

mweinelt commented 3 years ago

Thank you!