Comments (3)
Haha, sorry to disappoint, but after some experimentation, it's quite clear that this API doesn't make sense. Have a look at this test:
def test_wraps_wrappers():
call_list = []
def call_list_appender(func):
@wraps(func)
def appender(*a, **kw):
call_list.append((a, kw))
return func(*a, **kw)
return appender
class Num(object):
def __init__(self, num):
self.num = num
@call_list_appender
@classmethod
def added(cls, x, y=1):
return cls(x + y)
assert Num(1).num == 1
assert Num.added(0, 2).num == 2
assert len(call_list) == 1
All the details aside, the func
that is passed to call_list_appender
is a classmethod
instance. Classmethods are not callable objects. Done deal. Pretty sure this is mentioned in Graham's gigantic decorator posts, too.
The solve is to simply reverse the order of the decoration in your code, and add better exception messaging to boltons, of course:
...
@classmethod
@call_list_appender
def added(cls, x, y=1):
return cls(x + y)
...
The above works fine for me. This is one of those corner cases that makes wrapt so complex, and another reason why I only call out wraps as a replacement for decorator.py, not wrapt. I'll leave this issue open until I have those boltons exceptions in place.
from boltons.
Well, you could simplify this to the fact that it’s about descriptors in general. :) I only used classmethods as a concrete example. And yeah, shit’s complicated but descriptors happen.
from boltons.
(please ping me when you release this fix so I can update the error message in the post :))
from boltons.
Related Issues (20)
- Test failure with Python 3.11 HOT 1
- Tag for the 23.0.0 release is missing HOT 1
- Include tests in future pypi sdist tarball HOT 5
- Convert list of dict items to list of string items
- `ParsedException.from_string(text).to_string() == text` property violated due to anchors
- `boltons.ecoutils` `23.0.0` breaks `pdb` interactive prompt in `pytest` debug sessions HOT 4
- Non-empty `dictutils.OMD` cannot be loaded from `pickle` HOT 1
- RFC: Make boltons Python 3.7+ only. HOT 8
- Support in-place union for `dictutils.OrderedMultiDict` HOT 1
- [Feature request] Parametrize the delimiter to make glom use any kind of Path delimiter, not just `.` HOT 1
- wraps loses keywords
- chunked filter HOT 3
- tracking some ideas HOT 3
- LRU .values() and dict return old entries HOT 3
- call _orig_default identity
- Names in `boltons.strutils.__all__` with no definitions
- Missing git tags for 23.1.0 & 23.1.1 releases HOT 1
- iterutils.get_path has undocumented path as string parameter HOT 1
- 23.1.1: pytest (8.1.0) fail HOT 3
- Build fails with Python 3.13 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boltons.