Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
69c1c73d
Commit
69c1c73d
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
coverage
parent
0018ac45
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
satella/coding/debug/__init__.py
+9
-0
9 additions, 0 deletions
satella/coding/debug/__init__.py
satella/coding/debug/typecheck.py
+71
-0
71 additions, 0 deletions
satella/coding/debug/typecheck.py
with
80 additions
and
1 deletion
.gitignore
+
0
−
1
View file @
69c1c73d
...
...
@@ -48,7 +48,6 @@ docs/_templates
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
...
...
This diff is collapsed.
Click to expand it.
satella/coding/debug/__init__.py
0 → 100644
+
9
−
0
View file @
69c1c73d
# coding=UTF-8
"""
Things that run only during debug
If __debug__ is False, they will short-path themselves
"""
from
__future__
import
print_function
,
absolute_import
,
division
from
satella.coding.debug.typecheck
import
typed
\ No newline at end of file
This diff is collapsed.
Click to expand it.
satella/coding/debug/typecheck.py
0 → 100644
+
71
−
0
View file @
69c1c73d
# coding=UTF-8
"""
Decorator for debug-time typechecking
"""
from
__future__
import
print_function
,
absolute_import
,
division
import
six
import
logging
import
types
import
functools
logger
=
logging
.
getLogger
(
__name__
)
def
typed
(
*
t_args
,
**
t_kwargs
):
"""
Use like:
@typed(int, six.text_type)
def display(times, text):
...
int will automatically include long for checking (Python 3 compatibility)
If you want to check for None, type (None, )
None for an argument means
"
do no checking
"
, (None, ) means
"
type must be NoneType
"
You can pass tuples or lists to match for multiple types
:param t_args:
:param t_kwargs:
:return:
"""
def
typeinfo_to_tuple_of_types
(
typeinfo
):
if
typeinfo
is
None
:
return
(
types
.
NoneType
,
)
elif
typeinfo
==
int
and
six
.
PY2
:
return
six
.
integer_types
else
:
if
isinstance
(
typeinfo
,
(
tuple
,
list
)):
new_tup
=
[]
for
elem
in
typeinfo
:
new_tup
.
extend
(
typeinfo_to_tuple_of_types
(
elem
))
return
tuple
(
new_tup
)
else
:
return
(
typeinfo
,
)
t_args
=
[(
typeinfo_to_tuple_of_types
(
x
)
if
x
is
not
None
else
None
)
for
x
in
t_args
]
def
outer
(
fun
):
if
not
__debug__
:
return
fun
@functools.wraps
(
fun
)
def
inner
(
*
args
,
**
kwargs
):
if
isinstance
(
fun
,
types
.
MethodType
):
# instancemethod or classmethod
cargs
=
args
[
1
:]
else
:
cargs
=
args
for
argument
,
typedescr
in
zip
(
cargs
,
t_args
):
if
typedescr
is
not
None
:
if
not
isinstance
(
argument
,
typedescr
):
raise
TypeError
(
'
Got %s, expected %s
'
%
(
argument
,
typedescr
))
return
fun
(
*
args
,
**
kwargs
)
return
inner
return
outer
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment