Monkey patching support
オープン
まだ誰も着手していません。
topic: feature
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
説明
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)
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Protocol ベースの許可属性拡張を含む、提案されている Dynamic と dynamic の例を確認し、その後、制約や異論がないか、7件のコメントからなる議論を読んでください。この issue は実装の準備が整ったものではなく、探索的なものです。完了するには、コード作業を開始する前に、合意された設計と issue で言及されている適切な PEP が必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 静か
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100