Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
neoppod
Commits
82d95846
Commit
82d95846
authored
Dec 13, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
interfaces: check signature of methods
parent
f419f974
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
13 deletions
+51
-13
neo/lib/interfaces.py
neo/lib/interfaces.py
+51
-13
No files found.
neo/lib/interfaces.py
View file @
82d95846
...
...
@@ -17,25 +17,63 @@
import
inspect
from
functools
import
wraps
def
check_signature
(
reference
,
function
):
# args, varargs, varkw, defaults
A
,
B
,
C
,
D
=
inspect
.
getargspec
(
reference
)
a
,
b
,
c
,
d
=
inspect
.
getargspec
(
function
)
x
=
len
(
A
)
-
len
(
a
)
if
x
<
0
:
# ignore extra default parameters
if
x
+
len
(
d
)
<
0
:
return
False
del
a
[
x
:]
d
=
d
[:
x
]
or
None
elif
x
:
# different signature
# We have no need yet to support methods with default parameters.
return
a
==
A
[:
-
x
]
and
(
b
or
a
and
c
)
and
not
(
d
or
D
)
return
a
==
A
and
b
==
B
and
c
==
C
and
d
==
D
def
implements
(
obj
,
ignore
=
()):
tobj
=
type
(
obj
)
ignore
=
set
(
ignore
)
not_implemented
=
[]
wrong_signature
=
[]
if
isinstance
(
obj
,
type
):
tobj
=
obj
else
:
tobj
=
type
(
obj
)
mro
=
tobj
.
mro
()
mro
.
reverse
()
base
=
[]
for
name
in
dir
(
obj
):
method
=
getattr
(
obj
if
issubclass
(
tobj
,
type
)
or
name
in
obj
.
__dict__
else
tobj
,
name
)
if
inspect
.
ismethod
(
method
):
for
x
in
mro
:
try
:
method
.
__abstract__
ignore
.
remove
(
name
)
except
KeyError
:
not_implemented
.
append
(
name
)
x
=
getattr
(
x
,
name
)
break
except
AttributeError
:
not_implemented
.
extend
(
func
.
__name__
for
func
in
getattr
(
method
,
"__requires__"
,
())
if
not
hasattr
(
obj
,
func
.
__name__
))
assert
not
ignore
,
ignore
assert
not
not_implemented
,
not_implemented
pass
if
hasattr
(
x
,
"__abstract__"
)
or
hasattr
(
x
,
"__requires__"
):
base
.
append
((
name
,
x
.
__func__
))
try
:
while
1
:
name
,
func
=
base
.
pop
()
x
=
getattr
(
obj
,
name
)
if
x
.
im_class
is
tobj
:
x
=
x
.
__func__
if
x
is
func
:
try
:
x
=
func
.
__requires__
except
AttributeError
:
try
:
ignore
.
remove
(
name
)
except
KeyError
:
not_implemented
.
append
(
name
)
else
:
base
.
extend
((
x
.
__name__
,
x
)
for
x
in
x
)
elif
not
check_signature
(
func
,
x
):
wrong_signature
.
append
(
name
)
except
IndexError
:
# base empty
assert
not
ignore
,
ignore
assert
not
not_implemented
,
not_implemented
assert
not
wrong_signature
,
wrong_signature
return
obj
def
_set_code
(
func
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment