Monkey patching support
まだ誰も着手していません。
評価
調査の方向性
まず、Protocol ベースの許可属性拡張を含む、提案されている Dynamic と dynamic の例を確認し、その後、制約や異論がないか、7件のコメントからなる議論を読んでください。この issue は実装の準備が整ったものではなく、探索的なものです。完了するには、コード作業を開始する前に、合意された設計と issue で言及されている適切な PEP が必要です。
索引モデルが issue の本文から書いたものです。
説明
These are just some not terribly well though out ideas about possible monkey support in typing. This would need a proper PEP if it was ever implemented, but I just want to record my ideas here:
# foo accepts a date object, but allows to add and access
# unknown attributes at runtime. It basically treats date
# as having __getattr__()/__setattr__() methods.
def foo(date: Dynamic[datetime.date]) -> None:
date.my_attr = 123
print(date.added_by_called)
# typing.dynamic() is a no-op at runtime and basically an alias
# for cast(Generic[X], y) at type-check time, where X is the
# type of y.
# In this example, dt has type Dynamic[datetime.date].
dt = dynamic(datetime.date.today())
foo(dt)
# The following would also work:
foo(datetime.date.today())
other_dt: datetime.date = dt
A possible extensions would be to define the allowed monkey-patched attributes. Something like:
class Monkey(Protocol):
donkey: int
def foo(dt: Dynamic[datetime.date, Monkey]) -> None:
# ok:
print(dt.year)
dt.donkey += 3
# errors:
print(dt.kong)
dt.donkey += ""
dt = dynamic(datetime.date.today(), Monkey)
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/typing のほかの issue
-
topic: typing spec
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
topic: typing spec
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
topic: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
topic: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
topic: conformance tests topic: typing spec
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
似ている issue
-
Add: hunch オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DiamondLightSource/dodal#2211 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openml/openml-python#1749 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sipyourdrink-ltd/bernstein#6191 ·