NCAS-CMS / NCAS-CMS/cf-python

Convert schema-like objects to dataclasses

Open
#943 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code tidy
Dominant language
Python
Stars
150
Forks
23
Avg merge
1d 11h
Merged PRs (30d)
2

Description

As well as incorporating enumerations (see #942), there are objects in the codebase where we could convert to further data classes in order to better encode and handle their schema-like nature. Though we should only do so if a genuinely useful case for the logic using them, to avoid over-engineering.

An immediate example I see is from the parallel dictionaries in the constants module, e.g. the formula term system, where the same key space for the CF-supported Parametric Vertical Coordinates are spread across four parallel dicts which each define constraints set out in Appendix D of the CF Conventions:

https://github.com/NCAS-CMS/cf-python/blob/8c760f82ed119cdda0ad041bc9deec49f3bc15d4/cf/constants.py#L212-L494

and where conversion to data classes of a template similar to the following would make the underlying schema explicit and improve readability/maintainability:

from dataclasses import dataclass

@dataclass(frozen=True)
class FormulaDefinition:
    standard_names: dict
    units: dict
    max_dimensions: dict
    computed_standard_names: dict

But we can systematically survey the codebase for further candidates, ideally at the same time as we plan #942.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the parallel dictionaries in constants.py, especially the formula term system and the CF-supported Parametric Vertical Coordinates section linked in the issue. Survey the codebase alongside issue #942 for other schema-like objects, and consider only candidates with a genuinely useful consumer; done means the worthwhile cases have explicit dataclass-based schemas without over-engineering.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.