mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
Add a context manager for increasing indents
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
from jedi._compatibility import encoding, is_py3, u
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
from jedi._compatibility import encoding, is_py3, u
|
||||||
|
|
||||||
_inited = False
|
_inited = False
|
||||||
|
|
||||||
@@ -76,15 +78,21 @@ def reset_time():
|
|||||||
def increase_indent(func):
|
def increase_indent(func):
|
||||||
"""Decorator for makin """
|
"""Decorator for makin """
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
global _debug_indent
|
with increase_indent_cm():
|
||||||
_debug_indent += 1
|
|
||||||
try:
|
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
finally:
|
|
||||||
_debug_indent -= 1
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def increase_indent_cm():
|
||||||
|
global _debug_indent
|
||||||
|
_debug_indent += 1
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
_debug_indent -= 1
|
||||||
|
|
||||||
|
|
||||||
def dbg(message, *args, **kwargs):
|
def dbg(message, *args, **kwargs):
|
||||||
""" Looks at the stack, to see if a debug message should be printed. """
|
""" Looks at the stack, to see if a debug message should be printed. """
|
||||||
# Python 2 compatibility, because it doesn't understand default args
|
# Python 2 compatibility, because it doesn't understand default args
|
||||||
|
|||||||
Reference in New Issue
Block a user