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
b30a8544
Commit
b30a8544
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
e934c4e9
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
satella/coding/typecheck.py
+11
-16
11 additions, 16 deletions
satella/coding/typecheck.py
setup.cfg
+1
-1
1 addition, 1 deletion
setup.cfg
tests/test_coding/test_debug.py
+12
-2
12 additions, 2 deletions
tests/test_coding/test_debug.py
with
24 additions
and
19 deletions
satella/coding/typecheck.py
+
11
−
16
View file @
b30a8544
...
@@ -322,7 +322,6 @@ def _do_if_not_type(var, type_, fun='default'):
...
@@ -322,7 +322,6 @@ def _do_if_not_type(var, type_, fun='default'):
if
not
istype
(
var
,
type_
):
if
not
istype
(
var
,
type_
):
if
fun
==
'
default
'
:
if
fun
==
'
default
'
:
print
(
type_
)
if
type_
[
0
]
==
type
(
None
):
if
type_
[
0
]
==
type
(
None
):
return
None
return
None
else
:
else
:
...
@@ -428,21 +427,20 @@ def coerce(*t_args, **t_kwargs):
...
@@ -428,21 +427,20 @@ def coerce(*t_args, **t_kwargs):
return
outer
return
outer
def
checked_coerce
(
*
t_args
,
**
t_kwargs
):
def
checked_coerce
(
*
t_args
,
**
t_kwargs
):
"""
#todo banana banana banana
"""
"""
#todo banana banana banana
"""
def
ptc
(
item
):
def
ptc
(
item
,
pt
=
list
):
if
item
is
None
:
if
item
is
None
:
return
None
,
None
return
None
,
None
elif
isinstance
(
item
,
t
uple
):
elif
isinstance
(
item
,
p
t
):
if
len
(
item
)
==
2
:
if
len
(
item
)
==
2
:
return
item
[
0
],
item
[
1
]
return
item
[
0
],
item
[
1
]
return
item
,
None
return
item
,
None
def
sselector
(
q
,
z
,
operator
=
None
):
def
sselector
(
q
,
z
,
operator
=
None
,
pt
=
list
):
print
(
q
,
z
)
s
=
ptc
(
q
,
pt
=
pt
)[
z
]
s
=
ptc
(
q
)[
z
]
print
(
s
,
z
)
if
s
is
None
and
operator
is
None
:
if
s
is
None
and
operator
is
None
:
return
None
return
None
return
__typeinfo_to_tuple_of_types
(
s
,
operator
=
operator
)
return
__typeinfo_to_tuple_of_types
(
s
,
operator
=
operator
)
...
@@ -455,10 +453,8 @@ def checked_coerce(*t_args, **t_kwargs):
...
@@ -455,10 +453,8 @@ def checked_coerce(*t_args, **t_kwargs):
for
argument
,
typedescr
in
six
.
moves
.
zip_longest
(
args
,
t_args_c
)]
for
argument
,
typedescr
in
six
.
moves
.
zip_longest
(
args
,
t_args_c
)]
t_retarg
=
t_kwargs
.
get
(
'
returns
'
,
None
)
t_retarg
=
t_kwargs
.
get
(
'
returns
'
,
None
)
t_retarg_t
=
sselector
(
t_retarg
,
0
)
t_retarg_t
=
sselector
(
t_retarg
,
0
,
pt
=
tuple
)
t_retarg_c
=
sselector
(
t_retarg
,
1
,
operator
=
__NOP
)
t_retarg_c
=
sselector
(
t_retarg
,
1
,
operator
=
__NOP
,
pt
=
tuple
)
print
(
'
t_args_t=%s, t_args_c=%s, t_retarg_t=%s t_retarg_c=%s
'
%
(
t_args_t
,
t_args_c
,
t_retarg_t
,
t_retarg_c
))
def
outer
(
fun
):
def
outer
(
fun
):
@functools.wraps
(
fun
)
@functools.wraps
(
fun
)
...
@@ -471,11 +467,10 @@ def checked_coerce(*t_args, **t_kwargs):
...
@@ -471,11 +467,10 @@ def checked_coerce(*t_args, **t_kwargs):
type
(
argument
),
typedescr
))
type
(
argument
),
typedescr
))
rt
=
fun
(
*
argify
(
args
),
**
kwargs
)
rt
=
fun
(
*
argify
(
args
),
**
kwargs
)
print
(
t_retarg_t
)
if
not
istype
(
rt
,
t_retarg_t
):
# if not istype(rt, t_retarg_t):
raise
TypeError
(
'
Returned %s, expected %s
'
%
(
# raise TypeError('Returned %s, expected %s' % (
type
(
rt
),
t_retarg_t
))
# type(rt), t_retarg_t))
#
return
_do_if_not_type
(
rt
,
t_retarg_c
)
return
_do_if_not_type
(
rt
,
t_retarg_c
)
return
inner
return
inner
return
outer
return
outer
...
...
This diff is collapsed.
Click to expand it.
setup.cfg
+
1
−
1
View file @
b30a8544
[metadata]
[metadata]
name
= satella
name
= satella
version
= 2.0.19rc
2
version
= 2.0.19rc
3
description
-file = README.md
description
-file = README.md
author
= Piotr Maślanka
author
= Piotr Maślanka
author_email
= piotrm@smok.co
author_email
= piotrm@smok.co
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_debug.py
+
12
−
2
View file @
b30a8544
...
@@ -26,13 +26,23 @@ class TestTypecheck(unittest.TestCase):
...
@@ -26,13 +26,23 @@ class TestTypecheck(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
lambda
:
Lol
().
zomg
(
'
a
'
))
self
.
assertRaises
(
TypeError
,
lambda
:
Lol
().
zomg
(
'
a
'
))
Lol
().
lel
([],
{},
(),
set
([
1
]),
lambda
a
:
None
)
Lol
().
lel
([],
{},
(),
set
([
1
]),
lambda
a
:
None
)
def
test_che_co2
(
self
):
@checked_coerce
((
int
,
None
))
def
p
(
a
):
return
a
p
(
5
)
p
(
None
)
self
.
assertRaises
(
TypeError
,
lambda
:
p
(
5.0
))
def
test_checked_coerce
(
self
):
def
test_checked_coerce
(
self
):
@checked_coerce
(
(
(
str
,
int
),
int
)
,
returns
=
(
int
,
float
))
@checked_coerce
(
[
(
str
,
int
),
int
]
,
returns
=
(
int
,
float
))
def
testa
(
a
):
def
testa
(
a
):
return
a
return
a
self
.
assertRaises
(
TypeError
,
lambda
:
testa
(
5.0
))
self
.
assertRaises
(
TypeError
,
lambda
:
testa
(
5.0
))
self
.
assertEqual
(
testa
(
'
5
'
),
5.0
)
self
.
assertEqual
(
testa
(
'
5
'
),
5.0
)
self
.
assertEqual
(
testa
(
5
),
5.0
)
self
.
assertEqual
(
testa
(
5
),
5.0
)
...
...
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