Convert schema-like objects to dataclasses

未關閉
#943 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
冷清
技術堆疊
python
領域
data

研究方向

先檢視 constants.py 中的平行字典,尤其是 formula term system,以及 issue 中連結的 CF-supported Parametric Vertical Coordinates 區段。搭配 issue #942 探查程式碼庫中的其他類似 schema 的物件,並且只考慮具有真正實用 consumer 的候選項;當值得處理的案例都具備明確的、基於 dataclass 的 schemas,且沒有過度設計時,即可視為完成。

由索引模型根據 Issue 內容生成。

描述

code tidy

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.

主要語言
Python
星號
151
分支
23
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

NCAS-CMS/cf-python 的其他 Issue

查看 NCAS-CMS/cf-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。