Implementation of `has` macro is incomplete
まだ誰も着手していません。
評価
調査の方向性
src/celpy/evaluation.py の 1273 行付近にある has の実装から始め、MessageType が省略された protobuf フィールドとデフォルト値が設定された protobuf フィールドをどのように表現しているかを追ってください。方針を選ぶ前に、最小限の protobuf の例で報告された動作を再現してください。has が文書化された proto2 と proto3 の presence ルールに従い、デフォルト値と設定済みフィールドを混同しなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
The has macro is implemented by visiting the child nodes and returning true if there was not a CELEvalError. However, this makes it impossible for Protobuf messages to be handled properly.
The docstring describes the algorithm:
If e evaluates to a protocol buffers version 2 message and f is a defined field:
If f is a repeated field or map field, has(e.f) indicates whether the field is non-empty.
If f is a singular or oneof field, has(e.f) indicates whether the field is set.
If e evaluates to a protocol buffers version 3 message and f is a defined field:
If f is a repeated field or map field, has(e.f) indicates whether the field is non-empty.
If f is a oneof or singular message field, has(e.f) indicates whether the field is set.
If f is some other singular field, has(e.f) indicates whether the field's value is its default value (zero for numeric fields, false for booleans, empty for strings and bytes).
However, as far as I can tell, this is impossible to implement correctly no matter what. If you have a MessageType populated by omitting fields that are not present, you get incorrect behavior since unset fields are null instead of their default values. If you have a MessageType populated by setting default values, you get incorrect behavior because has returns true for fields that it shouldn't. What is needed is for has to return false while still populating the default value.
I don't currently have a minimal reproduction, in part because the library I am currently working on does not actually use the cel-python MessageType, but instead uses its own (though I did try to use cel-python MessageType and ran into basically the same issue, so I am pretty sure, as long as I am not missing anything, that it is similarly applicable.) That said, I hope this explanation is enough to either point me in the right direction: it seems like I am either misunderstanding how to use cel-python, or it is simply missing support for this. I think that there needs to be a way for has to be specialized for a given type; idiomatically it'd be best, in my opinion, if has could somehow call __contains__; then Python types, including MessageType, could just implement __contains__ and __getitem__ to do the right thing.
I would be willing to try to submit a PR to rectify this in the future if this sounds like a real issue and my solution would be OK, but I don't currently have a good enough understanding of how lark-parser works, so it may not be something I have time to approach for the moment.
- 主要言語
- Python
- スター
- 174
- フォーク
- 40
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloud-custodian/cel-python のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloud-custodian/cel-python#180 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
cloud-custodian/cel-python#194 ·
-
documentation enhancement tracking
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
cloud-custodian/cel-python#182 ·
-
Refresh Features オープンdependencies
cloud-custodian/cel-python#172 · コメント 2 件 · 担当者 1 名 ·
-
enhancement
cloud-custodian/cel-python#169 · コメント 3 件 · 担当者 1 名 ·
cloud-custodian/cel-python の issue をすべて見る
似ている issue
-
bug confirmed issue
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
open-webui/open-webui#30750 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 90/100