graviti.portex.param#

Parameter releated classes.

Module Contents#

Classes#

Param

Represents a parameter of a portex type.

Params

Represents all parameters of a portex type.

Functions#

param(default = Parameter.empty, options = None, ptype = PTYPE.Any)

The factory function of Param.

graviti.portex.param.param(default=Parameter.empty, options=None, ptype=PTYPE.Any)[source]#

The factory function of Param.

Parameters
  • default (Any) – The default value of the parameter.

  • options (Optional[Iterable[Any]]) – All possible values of the parameter.

  • ptype (graviti.portex.ptype.PType) – The parameter type.

Returns

A tuple which contains “default”, “options” and “ptype”.

Return type

Any

class graviti.portex.param.Param(name, default=_empty, options=None, ptype=PTYPE.Any)[source]#

Bases: inspect.Parameter

Represents a parameter of a portex type.

Parameters
  • name (str) – The name of the parameter.

  • default (Any) – The default value of the parameter.

  • options (Optional[Iterable[Any]]) – All possible values of the parameter.

  • ptype (graviti.portex.ptype.PType) – The parameter type.

classmethod from_pyobj(cls, pyobj, ptype=PTYPE.Any)[source]#

Create Param instance from python dict.

Parameters
  • pyobj (Dict[str, Any]) – A python dict representing a parameter.

  • ptype (graviti.portex.ptype.PType) – The parameter type.

Returns

A Param instance created from the input python dict.

Return type

Param

property required(self)[source]#

Whether this parameter is a required parameter.

Returns

True for required and False for non-required parameter.

Return type

bool

to_pyobj(self)[source]#

Dump the instance to a python dict.

Returns

A python dict representation of the Param.

Return type

Dict[str, Any]

check(self, arg)[source]#

Check the validity of the parameter.

Parameters

arg (Any) – The argument which needs to be checked.

Returns

The argument after checking.

Raises

ValueError – Raise when the argument is not in options.

Return type

Any

load(self, content, imports)[source]#

Create an instance of the parameter type from the python content.

Parameters
Returns

An instance of the parameter type.

Return type

Any

dump(self, arg)[source]#

Dump the parameter type instance into the python presentation.

Parameters

arg (Any) – The parameter type instance.

Returns

The python presentation of the input instance.

Return type

Any

class graviti.portex.param.Params(values=None)[source]#

Bases: graviti.utility.UserMapping[str, Param]

Represents all parameters of a portex type.

Parameters

values (Optional[Mapping[str, Param]]) – The parameters mapping.

classmethod from_pyobj(cls, pyobj, keys)[source]#

Create Params instance from python list.

Parameters
  • pyobj (List[Dict[str, Any]]) – A python dict representing parameters.

  • keys (Dict[str, Any]) – A python dict containing parameter types.

Returns

A Params instance created from the input python list.

Return type

Params

to_pyobj(self)[source]#

Dump the instance to a python list.

Returns

A python list representation of the Params.

Return type

List[Dict[str, Any]]

add(self, value)[source]#

Add a parameter.

Parameters

value (Param) – The parameter which needs to be added to this instance.

Raises

KeyError – When the parameter name is duplicated.

Return type

None

update(self, values)[source]#

Update the parameters.

Parameters

values (Mapping[str, Param]) – The parameters which need to be updated to this instance.

Return type

None

get_signature(self)[source]#

Get the python inspect Signature from parameters.

Returns

The Signature instance created by all parameters in this instance.

Return type

inspect.Signature