Skip to content

Commit

Permalink
Fix parameter signature check (#664)
Browse files Browse the repository at this point in the history
* Fix parameter signature check

* fix: import as

* Update cdci_data_analysis/analysis/parameters.py

Co-authored-by: Gabriele Barni <[email protected]>

---------

Co-authored-by: Gabriele Barni <[email protected]>
  • Loading branch information
dsavchenko and burnout87 authored Feb 28, 2024
1 parent 2696008 commit 2b9cf7e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cdci_data_analysis/analysis/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

from typing import Union
from inspect import signature
from inspect import Parameter as call_parameter
from .exceptions import RequestNotUnderstood

from jsonschema import validate, ValidationError, SchemaError
Expand Down Expand Up @@ -520,7 +521,8 @@ def from_owl_uri(cls,
if python_subclass.matches_owl_uri(owl_superclass_uri):
logger.info("will construct %s by owl_uri %s", python_subclass, owl_superclass_uri)
call_kwargs = {}
call_signature = signature(python_subclass)
call_signature = signature(python_subclass)
var_kw_signature = call_parameter.VAR_KEYWORD in [x.kind for x in call_signature.parameters.values()]

for restr, overr_kw, kw_name in [(par_format, 'format_kw', 'par_format'),
(par_format, 'default_format_kw', 'par_default_format'),
Expand All @@ -531,7 +533,7 @@ def from_owl_uri(cls,
(allowed_values, 'notexist', 'allowed_values')]:
if restr is not None:
par_kw = getattr(python_subclass, overr_kw, kw_name)
if par_kw in call_signature.parameters:
if var_kw_signature or par_kw in call_signature.parameters:
call_kwargs[par_kw] = restr
else:
logger.error(("according to ontology, owl_uri %s parameter have %s=%s "
Expand All @@ -540,7 +542,7 @@ def from_owl_uri(cls,
owl_uri, par_kw, restr, python_subclass)

for par_name, par_value in kwargs.items():
if par_name in call_signature.parameters:
if var_kw_signature or par_name in call_signature.parameters:
if par_name in call_kwargs.keys():
logger.warning("overriding ontology-derived value of the %s keyword of %s with explicitly set value %s",
par_name, python_subclass, par_value)
Expand Down

0 comments on commit 2b9cf7e

Please sign in to comment.