Giter Club home page Giter Club logo

micheles's People

Contributors

micheles avatar

Watchers

 avatar

micheles's Issues

Please add license file

While it is easy for me to see that this is under a BSD license on this site, I 
would prefer that you had a LICENSE.txt file in the project filled in with your 
name and the appropriate copyright year(s). That just makes it that much easier 
to get things right when including it in another project.

Original issue reported on code.google.com by [email protected] on 18 Dec 2014 at 6:25

decorator: Test failures with Python 3.3

$ PYTHONPATH="build/lib" python3.3 documentation3.py
**********************************************************************
File "documentation3.py", line 133, in __main__
Failed example:
    f1(0, 1)
Expected:
    Traceback (most recent call last):
       ...
    TypeError: f1() takes exactly 1 positional argument (2 given)
Got:
    Traceback (most recent call last):
      File "/usr/lib64/python3.3/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest __main__[3]>", line 1, in <module>
        f1(0, 1)
      File "documentation3.py", line 908, in memoize
        cache[key] = result = func(*args, **kw)
    TypeError: f1() takes 1 positional argument but 2 were given
**********************************************************************
File "documentation3.py", line 1063, in __main__.test_kwonlyargs
Failed example:
    func('a', 'b', 'c', 'd', 'e', y='y', z='z', cat='dog')
Expected:
    calling func with args ('a', 'b', 'c', 'd', 'e'), {'y': 'y', 'z': 'z', 'cat': 'dog'}
    ('y', 'z')
Got:
    calling func with args ('a', 'b', 'c', 'd', 'e'), {'cat': 'dog', 'z': 'z', 'y': 'y'}
    ('y', 'z')
**********************************************************************
2 items had failures:
   1 of  63 in __main__
   1 of   2 in __main__.test_kwonlyargs
***Test Failed*** 2 failures.

Original issue reported on code.google.com by [email protected] on 28 Sep 2012 at 11:41

2.3.2 no longer available

What steps will reproduce the problem?

$ pip install decorator==2.3.2
Downloading/unpacking decorator==2.3.2
  Could not find a version that satisfies the requirement decorator==2.3.2 (from versions: )
No distributions matching the version for decorator==2.3.2
Storing complete log in /home/alfborge/.pip/pip.log

What is the expected output? What do you see instead?

$ pip install decorator==3.3.1
Downloading/unpacking decorator==3.3.1
  Downloading decorator-3.3.1.tar.gz
  Running setup.py egg_info for package decorator

    warning: no previously-included files found matching 'Makefile'
Installing collected packages: decorator
  Running setup.py install for decorator

    warning: no previously-included files found matching 'Makefile'
Successfully installed decorator
Cleaning up...

Since we're using a product that has a requirement on decorator <= 2.3.2, we 
can no longer rely on pip to pull in our requirements.  If at all possible, 
please put back the old versions.

Thank you,
Alf Lervåg

Original issue reported on code.google.com by [email protected] on 11 May 2011 at 3:00

Doesn't work with "callable" `func` as documented in comment.

I'm trying to decorate a fabric `WrappedCallableTask` object. The comment on 
line 73 of `decorator.py` says `func` can be a class or callable, but not an 
instance method. `WrappedCallableTask` objects are callable.

This seems to be because `self.signature` is only assigned for actual functions 
(not callables). If I set it to an empty string instead, it works as expected.

Here's an interactive shell session demonstrating the problem.

In [1]: from fabric.api import task

In [2]: import decorator

In [3]: @decorator.decorator
   ...: def foo(func, *args, **kwargs):
   ...:         print 'foo'
   ...:         return func(*args, **kwargs)
   ...: 

In [4]: def x():
   ...:         print 'X'
   ...:     

In [5]: x
Out[5]: <function __main__.x>

In [6]: x()
X

In [7]: foo(x)
Out[7]: <function __main__.x>

In [8]: foo(x)()
foo
X

In [9]: y = task(x)

In [10]: y
Out[10]: <fabric.tasks.WrappedCallableTask at 0x107171350>

# `y` is callable, just like `x`.
In [11]: y()
X

# But I can't decorate it with a decorator that has been created by 
`decorator.decorator`.
In [12]: foo(y)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-c34da9d57b44> in <module>()
----> 1 foo(y)

<string> in foo(func)

/Users/tailee/.virtualenvs/ixcmembers/lib/python2.7/site-packages/decorator.pyc 
in decorator(caller, func)
    198         return FunctionMaker.create(
    199             func, "return _call_(_func_, %(shortsignature)s)",
--> 200             evaldict, undecorated=func, __wrapped__=func)
    201     else: # returns a decorator
    202         if inspect.isclass(caller):

/Users/tailee/.virtualenvs/ixcmembers/lib/python2.7/site-packages/decorator.pyc 
in create(cls, obj, body, evaldict, defaults, doc, module, addsource, **attrs)
    182             signature = None
    183             func = obj
--> 184         self = cls(func, name, signature, defaults, doc, module)
    185         ibody = '\n'.join('    ' + line for line in body.splitlines())
    186         return self.make('def %(name)s(%(signature)s):\n' + ibody,

/Users/tailee/.virtualenvs/ixcmembers/lib/python2.7/site-packages/decorator.pyc 
in __init__(self, func, name, signature, defaults, doc, module, funcdict)
    122         assert hasattr(self, 'name')
    123         if not hasattr(self, 'signature'):
--> 124             raise TypeError('You are decorating a non function: %s' % 
func)
    125 
    126     def update(self, func, **kw):

TypeError: You are decorating a non function: <fabric.tasks.WrappedCallableTask 
object at 0x107171350>

Original issue reported on code.google.com by [email protected] on 24 Jun 2014 at 7:04

Support for decorating methods [PATCH]

Hi Michele and thanks for your work on decorator.py! Sending attached a quick 
patch for allowing methods to be decorated. Tested on 2.7, I haven't jumped on 
Python 3 yet but shouldn't be too hard to adapt it.

Original issue reported on code.google.com by [email protected] on 30 Nov 2012 at 9:46

Attachments:

kwargs dict is not filled with kwargs

Hi Michele. Thanks for your great job!

Wrote a small decorator(django by default caches everything in 'default' cache):

def filesystem_cache(key_prefix, cache_time=None):
    """
    Caches function based on key_prefix and function args/kwargs.
    Stores function result in filesystem cache for a certain cache_time.
    """
    if cache_time:
        FILESYSTEM_CACHE_TIME = cache_time
    else:
        FILESYSTEM_CACHE_TIME = settings.CACHES['filesystem'].get('TIMEOUT')

    @decorator
    def wrapfunc(func, *args, **kwargs):
        ignore_cache = kwargs.pop('_ignore_cache', False)
        full_args = list()
        full_args.extend(args)
        for k, v in kwargs.items():
            full_args.append('%s:%s' % (str(k), str(v)))
        md5_args = md5_constructor(u':'.join([urlquote(var) for var in full_args]))
        cache_key = 'template.cache.%s.%s' % (key_prefix, md5_args.hexdigest())
        filesystem_cache = get_cache(FILESYSTEM_CACHE_NAME)
        cached_value = filesystem_cache.get(cache_key)
        if cached_value and not ignore_cache:
            # if cached value exists - return it
            return cached_value
        result = func(*args, **kwargs)
        filesystem_cache.set(cache_key, result, FILESYSTEM_CACHE_TIME)
        return result
    return wrapfunc

Everything works ok except that all args and kwargs for function fall into args 
section : 
In [2]: @filesystem_cache('bla')
   ...: def hello(a,b,c, d=10,e=12):
   ...:     print a
   ...:     print b
   ...:     print c
   ...:     print d
   ...:     return e

In [3]: hello(5,6,7, d=11,e=18)
> /home/dev/imax/mws/src/imax_main/utils.py(29)wrapfunc()
-> md5_args = md5_constructor(u':'.join([urlquote(var) for var in full_args]))
(Pdb) l
 24             full_args = list()
 25             full_args.extend(args)
 26             for k, v in kwargs.items():
 27                 full_args.append('%s:%s' % (str(k), str(v)))
 28             import pdb; pdb.set_trace()
 29  ->         md5_args = md5_constructor(u':'.join([urlquote(var) for var in full_args]))
 30             cache_key = 'template.cache.%s.%s' % (key_prefix, md5_args.hexdigest())
 31             filesystem_cache = get_cache(FILESYSTEM_CACHE_NAME)
 32             cached_value = filesystem_cache.get(cache_key)
 33             if cached_value and not ignore_cache:
 34                 # if cached value exists - return it
(Pdb) args
func = <function hello at 0xa63f454>
args = (5, 6, 7, 11, 18)
kwargs = {}
(Pdb) kwargs
{}

Why d and e kwargs are in args array ? Thanks !

Original issue reported on code.google.com by [email protected] on 13 Feb 2012 at 10:20

decorator doesn't pass keywords in wrapper function

An example to explain the issue (for python2.6):

@decorator
def example_decorator(func, *ar, **kw):
    print '*ar: ', ar
    print '**kw: ', kw
    func(*ar, **kw)

@example_decorator
def print_pars(z, x, c, v):
    pass

Output:

>>> print_pars(1, 2, 3, 4)
*ar: (1, 2, 3, 4)
**kw: {}

Thus, as you see, **kw dictionary is empty.

Original issue reported on code.google.com by [email protected] on 30 Oct 2011 at 5:56

decorator: documentation*.py doesn't return error when tests fail

documentation*.py scripts return a successful return code even when the tests 
fail. This makes it unsuitable for automated testing.

This happens because the result of doctest.testmod() is unused. It can be 
easily fixed through using it like:

  sys.exit(0 if doctest.testmod()[0] == 0 else 1)

Original issue reported on code.google.com by [email protected] on 20 Dec 2012 at 11:28

3.3.0 no longer available

What steps will reproduce the problem?
1. pip install decorator==3.3.0

What is the expected output? What do you see instead?
No distributions matching the version for decorator==3.3.0

What version of the product are you using? On what operating system?
3.3.0

Please provide any additional information below.
Where did it go? My build just broke.
I've tried to use 'pip install -e' but gave up (ignorance and out of time).
Thanks!

Original issue reported on code.google.com by [email protected] on 1 May 2011 at 7:48

Defaults are not supported

Thank you for a nice lib. Good job.  

I have a small issue when using default function or method values. Decorated 
function just fails.

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from decorator import decorator
>>>
>>> @decorator
... def function(value="default"):
...     print value
...
>>> function()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function() takes exactly 1 argument (0 given)
>>>


I suppose the code above supposed tp print "default"

I am using decorator==3.4.0

What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 5 Oct 2014 at 8:33

kwargs are passed as positional args to the decorator

What steps will reproduce the problem?

    #!/usr/bin/env python
    from decorator import decorator

    @decorator
    def f(func, *args, **kwargs):
        print([args, kwargs])
        func(*args, **kwargs)

    @f
    def foo(a, b, c=3):
        pass

    foo(1, 2, c=3)



What is the expected output? What do you see instead?
  Actual: [(1, 2, 3), {}]
  Expected: [(1, 2), {'c': 3}]

What version of the product are you using? On what operating system?
  decorator-3.3.1, Python 2.7.1+, Ubuntu

Original issue reported on code.google.com by [email protected] on 15 Jul 2011 at 8:44

IronPython only has _getframe(3) available when running with FullFrames enabled

What steps will reproduce the problem?
1. attempt to use decorator/_decorator.py from IronPython when not using 
FullFrames (either not using -X:FullFrames on the command line, or not 
compiling with PythonOptions.FullFrames)


What is the expected output? What do you see instead?

If you use with FullFrames, it will work. Else it will fail.

What version of the product are you using? On what operating system?

_decorator version 3.3.3 with IronPython 2.9.0.0 on Ubuntu 13.10, Linux.

Please provide any additional information below.

Patch:

https://github.com/ipython/ipython/pull/5055/files#diff-d32e06b23d48ae1c23fe66c8
601ebd97R142

Original issue reported on code.google.com by [email protected] on 10 Feb 2014 at 11:13

missing approx 8 support files

What steps will reproduce the problem?
1. acquire decorator-3.4.2
2. unpack
3.

What is the expected output? What do you see instead?
all the source files

What version of the product are you using? On what operating system?
decorator-3.4.2, gentoo linux

Please provide any additional information below.
files;

documentation .html .pdf .py 3.html 3.pdf 3.py
index.html test.py.

The previous release had most of them.

Original issue reported on code.google.com by [email protected] on 4 Apr 2015 at 9:27

Can't use decorators with function that have annotations which are built-ins or lambdas

Here's some example code:

from functools import partial
from operator import gt
from decorator import decorator

@decorator
def dec(func, *args, **kwargs):
    return func(*args, **kwargs)

@dec
def foo(bar: partial(gt, 5)) -> lambda x: x:
    pass


Here's the resulting traceback:

Traceback (most recent call last):
  File "foo.py", line 10, in <module>
    def foo(bar: partial(gt, 5)) -> lambda x: x:
  File "<string>", line 2, in dec
  File "/Users/kamil/.virtualenvs/covenant/lib/python3.2/site-packages/decorator.py", line 200, in decorator
    evaldict, undecorated=func, __wrapped__=func)
  File "/Users/kamil/.virtualenvs/covenant/lib/python3.2/site-packages/decorator.py", line 187, in create
    evaldict, addsource, **attrs)
  File "/Users/kamil/.virtualenvs/covenant/lib/python3.2/site-packages/decorator.py", line 154, in make
    code = compile(src, '<string>', 'single')
  File "<string>", line 1
    def foo(bar: functools.partial(<built-in function gt>, 5)) -> <function <lambda> at 0x1005cf2f8):


The BIF case could possibly be solved by doing some parsing of the annotations 
returned from getfullargspec but I'm not aware of any method of getting the 
code to define the lambda again. Perhaps it would be best to just filter out 
the annotations from the function signature, but still assign them to 
__annotations__ attribute of the resulting function?

Original issue reported on code.google.com by [email protected] on 11 Mar 2012 at 1:08

Can't decorate method, decorator(caller, func)

Solved with small patch


diff -r b3270ba22de7 decorator/src/decorator.py
--- a/decorator/src/decorator.py        Wed Nov 09 15:24:46 2011 +0100
+++ b/decorator/src/decorator.py        Sat Dec 10 01:14:49 2011 +0300
@@ -88,7 +88,7 @@
                 self.name = '_lambda_' 
             self.doc = func.__doc__
             self.module = func.__module__
-            if inspect.isfunction(func):
+            if inspect.isfunction(func) or inspect.ismethod(func):
                 argspec = getfullargspec(func)
                 for a in ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs',
                           'kwonlydefaults', 'annotations'):

Original issue reported on code.google.com by [email protected] on 9 Dec 2011 at 10:15

decorator: Test failure with Python 3.4

decorator 3.4.0 fails 1 test with Python 3.4.
(All tests pass with Python 2.6, 2.7, 3.2 and 3.3.)

$ PYTHONPATH="build/lib" python3.4 documentation3.py
**********************************************************************
File "documentation3.py", line 122, in __main__
Failed example:
    print(getargspec(f1))
Expected:
    ArgSpec(args=[], varargs='args', keywords='kw', defaults=None)
Got:
    ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None)
**********************************************************************
1 items had failures:
   1 of  68 in __main__
***Test Failed*** 1 failures.

Original issue reported on code.google.com by [email protected] on 18 Feb 2014 at 12:05

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.