Spec check misses NewType arguments of a generic group

オープン
#118 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@SimonHeybrock がすでに取り組んでいます。

2026年10月28日 から。

評価

この issue はまだ評価されていません。

説明

Summary

A spec may use a generic group parametrized with a NewType, such as essreduce's polarization markers. WorkflowSpec accepts it, but two such parameters serialize as one type, so a consumer of the serialized spec cannot tell them apart. It has the same root cause as scipp/sciline#250: pydantic names a generic model after its arguments, and gives every NewType the name NewType.

Reproducer

Polarizer = NewType('Polarizer', str)   # as in ess.reduce.polarization.types
Analyzer = NewType('Analyzer', str)
E = TypeVar('E')

class He3Cell(BaseModel, Generic[E]):
    pressure: float = Field(1.0, gt=0)

class Params(BaseModel):
    polarizer: He3Cell[Polarizer]
    analyzer: He3Cell[Analyzer]

spec = WorkflowSpec(..., params=Params, ...)   # accepted
schema = spec.serialize().params_schema
list(schema['$defs'])                          # [..., 'He3Cell_NewType_', ...]: one entry for both
schema['properties']['polarizer']              # ... 'dataType': 'He3Cell[NewType]'
schema['properties']['analyzer']               # ... 'dataType': 'He3Cell[NewType]'

Impact

Inside one process nothing goes wrong. The backend fits a reference by class identity (field_types.fits), and a PipelineBinding uses the class objects as sciline keys. A consumer that only has the serialized spec, such as a remote UI, matches an output to a parameter by dataType. It would offer a polarizer cell's output for the analyzer, and the other way round. No such consumer exists yet.

Proposal

Refuse it when the spec is made, as the rule "no NewType or type alias, at any depth" already intends (essspec ADR 0001). The check misses this case because field_types.arguments uses typing.get_args, which does not see the arguments of a parametrized pydantic model. Those are in __pydantic_generic_metadata__['args']. With them included, the existing message applies: a spec names a role by a class.

The fix at the source is in essreduce: define the markers as classes (class Polarizer: ...). That also fixes scipp/sciline#250 for these keys. Until then, a spec over essreduce's He3 workflow defines its own marker classes, and its binding maps them to essreduce's keys.

主要言語
Python
スター
0
フォーク
1
平均マージ
9時間 40分
マージ済み PR(30日)
60

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scipp/essapps のほかの issue

scipp/essapps の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。