Skip to content

Change constructs access API for consistency #132

@davidhassell

Description

@davidhassell

Current situation

The construct and construct_key methods take a single positional identity argument (https://github.com/NCAS-CMS/cfdm/blob/v1.8.8.0/cfdm/mixin/constructaccess.py#L301):

    def construct(self, identity, default=ValueError()):

Proposed change

The construct and construct_key methods take any number of positional arguments, as well as new keyword arguments:

    def construct(self, *identity, default=ValueError(), **filter_kwargs):

The **filter_kwargs are passed to the new Constructs.filter method for further selection flexibility.

This makes sense, as you can already match on multiple identities by providing a re.Pattern object, so it doesn't makes sense to restrict this to, say, *["latitude", "longitude"]

Consequences

The only possibly bad effect that this could have is for the default argument to be consumed by the *identity arguments if it is given as a positional parameter. For example, to Specify a default of None:

>>> f.construct('altitude', None)  # ok at v1.8.8.0
>>> f.construct('altitude', None)  # NOT ok with proposed change
>>> f.construct('altitude', default=None)  # ok with proposed change and at v1.8.8.0

Regardless of this potential for code breaking, I think this change will be beneficial.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions