Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit 7ae9862

Browse files
committed
updated methods in decorators.py, and added examples.py.
1 parent 004a351 commit 7ae9862

File tree

7 files changed

+80
-20
lines changed

7 files changed

+80
-20
lines changed

.idea/runConfigurations/examples.xml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PyDebug/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ def get_size(obj, seen=None):
2525
size += get_size(obj.__dict__, seen)
2626
elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
2727
size += sum([get_size(i, seen) for i in obj])
28-
return size
28+
return size
29+

src/PyDebug/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
version = '1.1.0'
3+
version = '1.2.0'

src/PyDebug/colors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import tkinter as tk
22

3+
__all__ = ['AllNamedColors', 'runTkColors']
4+
5+
6+
37
class AllNamedColors(object):
48
all_widgets = []
59
COLORS = [
@@ -108,5 +112,6 @@ def runTkColors():
108112
Colors = AllNamedColors()
109113
Colors.run()
110114

115+
111116
if __name__ == '__main__':
112-
runTkColors()
117+
runTkColors()

src/PyDebug/converters.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ def IsAttributePrivate(attr_name: str) -> bool:
88
return private_or_special_function_searcher.search(attr_name) is not None
99

1010

11-
def ObjectToDict(Object: any, MethodsToSkip: list or tuple = (), *, ShowAll: bool = False) -> dict:
11+
def ObjectToDict(Object: any, Skip: list or tuple = (), *, ShowAll: bool = False, IncludeCallable: bool = False) -> dict:
1212
"""
1313
Returns a dictionary of the public attributes of the given object provided;
1414
Filter out private or special functions (_private, __SuperPrivate, __special__).
1515
16-
:param ShowAll:
17-
:param MethodsToSkip:
18-
:param Object:
16+
:param IncludeCallable: doesn't include functions by default.
17+
:param ShowAll: remove all filters and show entire object.
18+
:param Skip: list of names to skip. i.e. certain method names when IncludeCallable is True.
19+
:param Object: the thing being inspected.
1920
:return:
2021
"""
2122
temp = {}
2223
for key in dir(Object):
23-
if key in MethodsToSkip: continue
24+
if key in Skip: continue
2425
if ShowAll or IsAttributePrivate(key):
2526
temp[key] = getattr(Object, key)
27+
if IncludeCallable and callable(temp[key]):
28+
del temp[key]
2629
return temp
2730

src/PyDebug/decorators.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
__all__ = ['debug', 'class_method_debug', 'check_time', 'debugTkinterEvent', 'pprint_debug']
1111

12+
DEFAULT_TAG = '\n_______________________________ "{0}" _______________________________'
1213

13-
14-
def class_method_debug(cls: str or type, tag: str = '\n________________________________________________________________'):
14+
def class_method_debug(cls: str or type, tag: str = DEFAULT_TAG):
1515
"""
1616
Print the function signature and return value
1717
@@ -38,7 +38,7 @@ def wrapper_debug(*args, **kwargs):
3838

3939
signature = ", ".join(args_repr + kwargs_repr) # 3
4040

41-
print(f"{tag} \n{cls}.{func.__name__}({signature})")
41+
print(f"{tag.format(f'{func.__module__}.{func.__qualname__}')} \n{cls}.{func.__name__}(\n{signature}\n)")
4242
result = func(*args, **kwargs)
4343
print(f"{func.__name__} returned {result!r}\n") # 4
4444

@@ -48,7 +48,7 @@ def wrapper_debug(*args, **kwargs):
4848

4949

5050

51-
def debug(func: callable, tag: str = '\n________________________________________________________________'):
51+
def debug(func: callable, tag: str = DEFAULT_TAG):
5252
"""
5353
Print the function signature and return value
5454
@@ -65,7 +65,7 @@ def wrapper_debug(*args, **kwargs):
6565

6666
signature = ", ".join(args_repr + kwargs_repr) # 3
6767

68-
print(f"{tag} \n{func.__name__}({signature})")
68+
print(f"{tag.format(f'{func.__module__}.{func.__qualname__}')} \n{func.__qualname__}(\n{signature}\n)")
6969
result = func(*args, **kwargs)
7070
print(f"{func.__name__} returned {result!r}\n") # 4
7171

@@ -74,7 +74,7 @@ def wrapper_debug(*args, **kwargs):
7474

7575

7676

77-
def pprint_debug(func: callable, tag: str = '\n________________________________________________________________'):
77+
def pprint_debug(func: callable, tag: str = DEFAULT_TAG):
7878
"""
7979
Print the function signature and return value
8080
@@ -84,9 +84,8 @@ def pprint_debug(func: callable, tag: str = '\n_________________________________
8484
"""
8585
@functools.wraps(func)
8686
def wrapper_debug(*args, **kwargs):
87-
signature = getPPrintStr({'args': kwargs, 'kwargs': args, })
88-
89-
print(f"{tag} \n{func.__name__}({signature})")
87+
signature = getPPrintStr({'kwargs': kwargs, 'args': args, })
88+
print(f"{tag.format(f'{func.__module__}.{func.__qualname__}')} \n{func.__qualname__}(\n{signature}\n)")
9089
result = func(*args, **kwargs)
9190
print(f"{func.__name__} returned {result!r}\n")
9291

@@ -95,7 +94,7 @@ def wrapper_debug(*args, **kwargs):
9594

9695

9796

98-
def check_time(*, cls: str or type = None, print_signature: bool = True, tag: str = '\n_______________________________check_time_______________________________'):
97+
def check_time(*, cls: str or type = None, print_signature: bool = True, tag: str = DEFAULT_TAG):
9998
"""
10099
Print the function signature and return value
101100
@@ -135,10 +134,10 @@ def timed(*args, **kwargs):
135134

136135

137136

138-
def debugTkinterEvent(func: callable, tag: str = '_______________________________TkinterEvent_______________________________'):
137+
def debugTkinterEvent(func: callable, tag: str = DEFAULT_TAG):
139138
@functools.wraps(func)
140139
def wrapper_debug(self, event: Event, *args, **kwargs):
141-
PRINT(f'{tag}\n{func.__class__}.{func.__name__}.{Event.__class__}', event.__dict__)
140+
PRINT(f'{tag.format("TkinterEvent")}\n{func.__class__}.{func.__name__}.{Event.__class__}', event.__dict__)
142141

143142
result = func(self, event, *args, **kwargs)
144143

src/examples.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import tkinter as tk
2+
from PyDebug import *
3+
4+
if __name__ == '__main__':
5+
6+
class test(object):
7+
@pprint_debug
8+
def pp_run(self, *args, **kwargs):
9+
pass
10+
@debug
11+
def run(self, *args, **kwargs):
12+
pass
13+
@debugTkinterEvent
14+
def tk_run(self, event: tk.Event):
15+
pass
16+
17+
t = test()
18+
19+
t.run()
20+
21+
t.pp_run()
22+
23+
evt = tk.Event()
24+
evt.widget = None
25+
evt.x = None
26+
evt.y = None
27+
t.tk_run(evt)
28+

0 commit comments

Comments
 (0)