When combined with @property methods, `instance` argument does not seem to match the docs
See original GitHub issueMy understanding from the documentation is that for decorated instance methods, you never should have to extract the self
arg, that it is always in instance
, not args
, and that wrapped
is already bound to instance
. However, this does not seem true when combined with the property decorator:
from pytest import fixture
from wrapt import decorator
@decorator
def wrapper(wrapped, instance, args, kwargs):
return {'instance':instance, 'args':args, 'kwargs': kwargs, 'wrapped':wrapped(*args, **kwargs)}
class Decorated:
@property
@wrapper
def prop(self, *args, **kwargs):
return {'self': self, 'args': args, 'kwargs':kwargs}
@fixture
def instance(): return Decorated()
@fixture
def result(instance): return instance.prop
def test_instance_is_sent_to_wrapped(instance, result): # passes
assert result['wrapped']['self'] is instance
def test_instance_arg_is_correct(instance, result): # fails
assert result['instance'] is instance
def test_instance_is_not_i_args(instance, result): # fails
assert instance not in result['args']
(running on python 3.7.8, wrapt 1.12.1, pytest 5.3.2)
This doesn’t seem intentional, and I suspect is @property
pulling some shenanigans. If these test don’t use @property
, and are modified to use a method, they pass. Also, if you grab the property descriptor, calling descriptor.fget
requires an instance arg, it isn’t bound.
Can this issue be fixed?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Property Functions - MSBuild - Microsoft Learn
Learn how to use property functions, which are calls to .NET Framework methods that appear in MSBuild property definitions.
Read more >Classes - Object-Oriented Programming in Python
If we call the class method from an instance, this parameter will contain the instance object, but if we call it from the...
Read more >functools — Higher-order functions and operations on callable ...
When func is a non-descriptor callable, an appropriate bound method is created dynamically. This behaves like a normal Python function when used as...
Read more >1.7.1 - jqwik User Guide
Since Gradle does not yet support JUnit platform reporting – see this Github ... At test runtime the exact parameter values of the...
Read more >Error.prototype.stack - JavaScript - MDN Web Docs - Mozilla
The non-standard stack property of an Error instance offers a trace of which ... MSDN docs also seem to match the PhantomJS implementation....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Old issue related to this with more thorough description of how to create a wrapper object for properties can be found at:
Here’s an example of my use case:
It’s similar to
functools.partial_method
, but I need more flexibility.