Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lscsoft
bilby
Commits
82bcd9c9
Verified
Commit
82bcd9c9
authored
5 years ago
by
Daniel Williams
Browse files
Options
Downloads
Patches
Plain Diff
Tidy up documentation on new functions.
parent
c4a66ec6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!608
Add support for inference of method arguments
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bilby/core/utils.py
+12
-4
12 additions, 4 deletions
bilby/core/utils.py
with
12 additions
and
4 deletions
bilby/core/utils.py
+
12
−
4
View file @
82bcd9c9
...
...
@@ -6,6 +6,7 @@ from math import fmod
import
argparse
import
traceback
import
inspect
import
types
import
subprocess
import
multiprocessing
from
importlib
import
import_module
...
...
@@ -42,9 +43,14 @@ def infer_parameters_from_function(func):
The function or method for which the parameters should be inferred.
Returns
-------
--
-------
list: A list of strings with the parameters
Raises
------
ValueError
If the object passed to the function is neither a function nor a method.
Notes
-----
In order to handle methods the ``type`` of the function is checked, and
...
...
@@ -54,7 +60,7 @@ def infer_parameters_from_function(func):
"""
if
isinstance
(
func
,
types
.
MethodType
):
# This is a method, remove the first two arguments
return
_
infer_args_from_
function_except_n_args
(
func
,
n
=
2
)
return
infer_args_from_
method
(
method
=
func
)
elif
isinstance
(
func
,
types
.
FunctionType
):
# It's a function, remove just the first argument
return
_infer_args_from_function_except_for_first_arg
(
func
=
func
)
...
...
@@ -62,6 +68,7 @@ def infer_parameters_from_function(func):
# Panic, I don't understand what I'm looking at
raise
ValueError
(
"
This doesn
'
t look like a function.
"
)
def
infer_args_from_method
(
method
):
"""
Infers all arguments of a method except for
'
self
'
...
...
@@ -73,7 +80,8 @@ def infer_args_from_method(method):
---------
list: A list of strings with the parameters
"""
return
_infer_args_from_function_except_for_first_arg
(
func
=
method
)
# This is a method, remove the first two arguments
return
_infer_args_from_function_except_n_args
(
func
=
method
,
n
=
2
)
def
_infer_args_from_function_except_n_args
(
func
,
n
=
1
):
...
...
@@ -115,7 +123,7 @@ def _infer_args_from_function_except_n_args(func, n=1):
parameters
=
inspect
.
getfullargspec
(
func
).
args
except
AttributeError
:
parameters
=
inspect
.
getargspec
(
func
).
args
del
(
parameters
[:
n
])
del
(
parameters
[:
(
n
-
1
)
])
return
parameters
...
...
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