Monkey patching support
还没有人认领这个 Issue。
评估
调研方向
首先审阅提议的 Dynamic 和 dynamic 示例,包括基于 Protocol 的允许属性扩展,然后阅读包含七条评论的讨论,以了解其中的约束或异议。此 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 小时
- 30 天内合并 PR
- 8
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 ·