Skip to content

Commit dcd7a2b

Browse files
committed
Attribute support
1 parent 8f83768 commit dcd7a2b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ modify ``/usr/lib/python3.6/sitecustomize.py`` making ``debug`` available in any
3333

3434
.. code:: python
3535
36-
from devtools import debug
37-
__builtins__['debug'] = debug
38-
36+
# add devtools debug to builtins
37+
try:
38+
from devtools import debug
39+
except ImportError:
40+
pass
41+
else:
42+
__builtins__['debug'] = debug
3943
4044
.. |BuildStatus| image:: https://travis-ci.org/samuelcolvin/python-devtools.svg?branch=master
4145
:target: https://travis-ci.org/samuelcolvin/python-devtools

devtools/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Debug:
6767
# 50 lines should be enough to make sure we always get the entire function definition
6868
frame_context_length = 50
6969
complex_nodes = (
70-
ast.Call,
70+
ast.Call, ast.Attribute,
7171
ast.IfExp, ast.BoolOp, ast.BinOp, ast.Compare,
7272
ast.DictComp, ast.ListComp, ast.SetComp, ast.GeneratorExp
7373
)

tests/test_main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ def test_simple_vars():
103103
)
104104

105105

106+
def test_attributes():
107+
class Foo:
108+
x = 1
109+
110+
class Bar:
111+
y = Foo()
112+
113+
b = Bar()
114+
v = debug.format(b.y.x)
115+
assert 'test_attributes: b.y.x = 1 (int)' in str(v)
116+
117+
106118
def test_eval():
107119
with pytest.warns(RuntimeWarning):
108120
v = eval('debug.format(1)')

0 commit comments

Comments
 (0)