TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

PEP 526: Variable declaration in Python

48 点作者 steinsgate将近 9 年前

12 条评论

alanfranzoni将近 9 年前
Bah. If you want a statically typed language, get a statically typed language.<p>What&#x27;s a type hint for if, after that, the user can actually pass a different type?
评论 #12267342 未加载
评论 #12267267 未加载
评论 #12268285 未加载
评论 #12267202 未加载
raverbashing将近 9 年前
Yeah, it seems it&#x27;s time to abandon Python since the static typing fundamentalists seem to be getting hold of it<p>Extremely frustrated by this decision and even though the multiple denials that it won&#x27;t become a statically typed language it&#x27;s clear that idea has changed
评论 #12267068 未加载
评论 #12267138 未加载
评论 #12267292 未加载
haney将近 9 年前
I see a ton of comments that are dismissing this but from my experience most code has implicit typing of some sort. This looks like a nice replacement for hand written input validation, if my function expects a number and I pass a string there are 3 options AFAIK:<p>1) I have the ability to define a type that&#x27;s required so that the function can&#x27;t be called without a numeric type.<p>2) I add boiler plate the the top of my function to validate that I&#x27;m receiving a number.<p>3) I forget to do 1 or 2 and I get a runtime error when a different developer inadvertently passes an incorrect type to my function.
berntb将近 9 年前
Where typing is really useful, in my experience, is in an external API.<p>Most heavily used libraries in most dynamic languages, not only Python, ought to have assertions with type checks for parameters. In the external API calls to the lib.<p>Inside of a lib you should have tests anyway, so type declarations shouldn&#x27;t be important.
toyg将近 9 年前
A very sad day. We were told type hints were just that, optional hints to help IDEs and such. Now they&#x27;re creeping into the language proper; IDEs will start adding them for you, and before you know it all &quot;serious codebases&quot; will be statically typed.<p>The beauty of python was that it could read like pseudocode; more and more special characters and notations are putting that idea to rest. I guess it&#x27;s the price to pay for mainstream success -- when banks get involved, everything becomes uber-formal and soul-crushing.
评论 #12267140 未加载
RodericDay将近 9 年前
Where can we voice our opposition to this?<p>If people really want their bulky IDEs to give them maximum help when introspecting a codebase, there should just be a TypeScript like superset of Python that those people can use.<p>This syntax is awful and will seriously cause antagonism in terms of what people consider &quot;pythonic&quot; and &quot;good code&quot;.
评论 #12280932 未加载
rilut将近 9 年前
Why [T]? Why not &lt;T&gt;? It confuses with array selection
评论 #12267142 未加载
评论 #12267149 未加载
webjunkie将近 9 年前
Why not the other way around:<p><pre><code> my_class_attr = ClassAttr[bool]: True </code></pre> This seems more familiar somehow.
评论 #12267109 未加载
denfromufa将近 9 年前
I wish mypy, cython, and numba type annotations converge to something common.
w8rbt将近 9 年前
Do the hints increase performance at all? I would think they could.
评论 #12267412 未加载
super_mario将近 9 年前
This is why Python 2.7 will just continue indefinitely.
crdoconnor将近 9 年前
That&#x27;s a lot of extra character overhead for not very much gain.
评论 #12267121 未加载
评论 #12267943 未加载