-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy path_internal.py
More file actions
39 lines (27 loc) · 855 Bytes
/
_internal.py
File metadata and controls
39 lines (27 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
These are internal helpers. Do not rely on their presence.
http://mail.python.org/pipermail/python-dev/2008-January/076194.html
"""
__all__ = ("monkeypatch_method", "monkeypatch_property")
def monkeypatch_method(cls):
"""
A decorator to add a single method to an existing class::
@monkeypatch_method(<someclass>)
def <newmethod>(self, [...]):
pass
"""
def decorator(func):
setattr(cls, func.__name__, func)
return func
return decorator
def monkeypatch_property(cls):
"""
A decorator to add a single method as a property to an existing class::
@monkeypatch_property(<someclass>)
def <newmethod>(self, [...]):
pass
"""
def decorator(func):
setattr(cls, func.__name__, property(func))
return func
return decorator