Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kwant
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joseph Weston
kwant
Commits
206a5389
Commit
206a5389
authored
7 years ago
by
Joseph Weston
Browse files
Options
Downloads
Patches
Plain Diff
make 'get_parameters' also return names of parameters that take defaults
parent
bbb864fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kwant/_common.py
+12
-7
12 additions, 7 deletions
kwant/_common.py
with
12 additions
and
7 deletions
kwant/_common.py
+
12
−
7
View file @
206a5389
...
...
@@ -92,9 +92,11 @@ def get_parameters(func):
Returns
-------
names : list
Positional, keyword and keyword only parameter names in the order
that they appear in the signature of
'
func
'
.
required_params : list
Names of positional, and keyword only parameters that do not have a
default value and that appear in the signature of
'
func
'
.
default_params : list
Names of parameters that have a default value.
takes_kwargs : bool
True if
'
func
'
takes
'
**kwargs
'
.
"""
...
...
@@ -102,9 +104,12 @@ def get_parameters(func):
pars
=
sig
.
parameters
# Signature.parameters is an *ordered mapping*
names
=
[
k
for
(
k
,
v
)
in
pars
.
items
()
if
v
.
kind
in
(
inspect
.
Parameter
.
POSITIONAL_OR_KEYWORD
,
inspect
.
Parameter
.
KEYWORD_ONLY
)]
required_params
=
[
k
for
(
k
,
v
)
in
pars
.
items
()
if
v
.
kind
in
(
inspect
.
Parameter
.
POSITIONAL_OR_KEYWORD
,
inspect
.
Parameter
.
KEYWORD_ONLY
)
and
v
.
default
is
inspect
.
_empty
]
default_params
=
[
k
for
(
k
,
v
)
in
pars
.
items
()
if
v
.
default
is
not
inspect
.
_empty
]
takes_kwargs
=
any
(
i
.
kind
is
inspect
.
Parameter
.
VAR_KEYWORD
for
i
in
pars
.
values
())
return
name
s
,
takes_kwargs
return
required_params
,
default_param
s
,
takes_kwargs
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