FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[Original HTTPS Page]
PythonDebugTools/src/PythonDebugTools/chains.py at master · Jakar510/PythonDebugTools · GitHub
This repository was archived by the owner on Jun 4, 2021. It is now read-only.
Jakar510
/
PythonDebugTools
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonDebugTools
/
src
/
PythonDebugTools
/
chains.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
80 lines (63 loc) · 2.65 KB
Breadcrumbs
PythonDebugTools
/
src
/
PythonDebugTools
/
chains.py
Copy path
File metadata and controls
80 lines (63 loc) · 2.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import
functools
from
typing
import
*
from
BaseExtensions
.
AutoCounter
import
AutoCounter
from
.
console
import
*
__all__
=
[
'chain'
,
'sub'
]
_counter
=
AutoCounter
()
def
chain
(
start_tag
:
str
=
pp
.
TITLE_TAG
,
end_tag
:
str
=
pp
.
END_TAG
,
start
:
int
=
1
):
"""
Print the function signature and return value
:param start:
:type start:
:param end_tag: a unique string to identify the ENDING of the chain in the console window.
:param start_tag: a unique string to identify the START of the chain in the console window.
:return:
"""
_counter
.
reset
(
start
=
start
)
def
wrapped
(
func
:
callable
):
"""
:param func: callable function to be debugged.
:return:
"""
@
functools
.
wraps
(
func
)
def
wrapper_debug
(
*
args
,
**
kwargs
):
name
=
GetFunctionName
(
func
)
tag
=
start_tag
.
format
(
name
)
signature
=
pp
.
getPPrintStr
({
'kwargs'
:
kwargs
,
'args'
:
args
, })
_start
=
f'
{
name
}
(
\n
{
signature
}
\n
)'
Print
(
pp
.
END_TAG
,
tag
,
_start
)
result
=
func
(
*
args
,
**
kwargs
)
_end
=
f'
{
name
}
returned:
{
pp
.
getPPrintStr
(
result
)
}
\n
'
Print
(
_end
,
end_tag
)
return
result
return
wrapper_debug
return
wrapped
def
_print_chain_signature
(
func
:
callable
,
tag
:
str
,
level
:
Union
[
int
,
AutoCounter
],
signature
:
bool
,
result
,
args
,
kwargs
):
assert
(
'{0}'
in
tag
)
if
signature
and
(
args
or
kwargs
):
name
=
GetFunctionName
(
func
)
_tag
=
tag
.
format
(
f'
{
level
}
-->
{
name
}
'
)
signature
=
pp
.
getPPrintStr
({
'args'
:
args
,
'kwargs'
:
kwargs
})
Print
(
_tag
,
f'
{
name
}
(
\n
{
signature
}
\n
)'
,
name
,
f'returned:
\n
{
pp
.
getPPrintStr
(
result
)
}
'
)
def
sub
(
level
:
int
=
None
,
*
,
tag
:
str
=
'-------------- level: {0}'
,
signature
:
bool
=
False
):
"""
Print the function signature [Optional] and return value.
:param level: optional positive non-zero intenger
:type level: int
:param signature: for sub-level method chains, prints it's signature. defaults to False.
# :param level: the call stack level. f() -> g() -> h() -> etc.
:param tag: a unique string to identify the output in the console window. must have one '{0}' for str.format() support.
:return:
"""
def
wrapped
(
func
:
callable
):
"""
:param func: callable function to be debugged.
:return:
"""
@
functools
.
wraps
(
func
)
def
wrapper_debug
(
*
args
,
**
kwargs
):
result
=
func
(
*
args
,
**
kwargs
)
_print_chain_signature
(
func
,
tag
,
level
or
_counter
(),
signature
,
result
,
args
,
kwargs
)
return
result
return
wrapper_debug
return
wrapped
Back
|
FazBrowse Home
|
New Git URL