TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python 3.5 type hinting in PyCharm 5

173 pointsby ceronmanover 9 years ago

14 comments

ghshephardover 9 years ago
Pretty impressive that the syntax:<p><pre><code> def greeting(name: str) -&gt; str: </code></pre> Turns out to be <i>backwards</i> compatible in Python3 before 3.5 (though not Python2, yet another reason, if you actually needed one, to start new stuff in Python3)
评论 #10625374 未加载
评论 #10624976 未加载
评论 #10624997 未加载
评论 #10631385 未加载
评论 #10625086 未加载
评论 #10629193 未加载
评论 #10625179 未加载
themartoranaover 9 years ago
Recently stumbled upon IntelliJ using the Go plugin package after a Rubyist friend of mine spoke very highly of RubyMine. I have to say I was incredibly impressed. I looked at it a couple years ago when I was mostly Python and it was ok, but it&#x27;s really stepped up its game - both feature-wise and visually.<p>The IntelliJ IDE set is really far better than I understood. IMHO.
评论 #10625888 未加载
cdnsteveover 9 years ago
I can see this being very useful in teams. Hell, its even useful for a single developer as a form of future documentation. I generally write code today and think, when I read this in 6 months and have no memory, how can I help my future self? For new code bases I&#x27;ll be adding this.
评论 #10625039 未加载
评论 #10624968 未加载
评论 #10626923 未加载
thomasahleover 9 years ago
I wonder why, given they call it &#x27;type hints&#x27;, they didn&#x27;t go for Haskell-like type comments:<p><pre><code> #greeting :: (str, int) -&gt; str def greeting(name, age): </code></pre> In fact, I wonder why more languages don&#x27;t adopt this syntax, since it greatly simplifies functions with very large types.
评论 #10627163 未加载
评论 #10628427 未加载
评论 #10629218 未加载
评论 #10629379 未加载
zurnover 9 years ago
There&#x27;s quite some dissonance between the artificial &quot;generics&quot; vs normal types. Why the concrete str type for strings, but not for lists? I realize there are implementation level arguments for it, but the resulting compromise does not seem good.<p>And specifying the concrete str type goes diametrically against the &quot;don&#x27;t check against a concrete type, embrace duck typing&quot; mantra that Python programmers are taught early.
评论 #10626286 未加载
评论 #10626229 未加载
评论 #10626908 未加载
2bitencryptionover 9 years ago
something that&#x27;s always had me a bit confused:<p>the type hinting in Python is just that -- <i>hinting,</i> right?<p>It&#x27;s for IDEs like PyCharm to use to generate better docs and to be more intelligent about suggestions when writing code. But what it does NOT do is inform the interpreter&#x2F;compiler about type information, correct?<p>I.e., Python3 code with perfectly implemented type hints would only make it easier on the developer, and not the interpreter&#x2F;compiler, yeah?
评论 #10625075 未加载
评论 #10625095 未加载
评论 #10626423 未加载
评论 #10626140 未加载
评论 #10625056 未加载
评论 #10625057 未加载
评论 #10625044 未加载
Animatsover 9 years ago
&quot;Type hinting&quot; without checking is kind of lame. If you&#x27;re going to have declarations such as<p><pre><code> def zero_all_vars(vars: Iterable[LoggedVar[int]]) -&gt; None: </code></pre> people are going to get them wrong some of the time. Dumping the checking problem on some IDE, with a very vague specification of what an error is, is not progress. If functions have type specifications, you should not be able to call them with the wrong type, ever. This is the job of the compiler and the run time system, not the IDE.<p>Somebody should stop Python&#x27;s little tin god before he creates another giant step backwards like the Python 2 to 3 mess.
评论 #10625511 未加载
评论 #10625677 未加载
评论 #10629309 未加载
评论 #10625624 未加载
评论 #10625744 未加载
doucheover 9 years ago
I have fond memories of using Python 8-10 years ago, but looking at it today, I&#x27;m not sure I see compelling reasons not to just use C# instead.<p>I can have real static typing if I want it. I can also have dynamic typing if I want that. I can use lambda functions. I have LINQ. I can use ScriptCS or some of the new Roslyn stuff if I want to use it as a scripting language. Unix support is not as great, but they are coming along with that. There&#x27;s no GIL.<p>Is there some killer feature for Python that I&#x27;m overlooking?
评论 #10625674 未加载
评论 #10625679 未加载
评论 #10625977 未加载
评论 #10625678 未加载
评论 #10626730 未加载
mark_l_watsonover 9 years ago
I like this. I use Ruby as a scripting language more often than Python and I would be happy to see similar additions to Ruby to improve code readability and IDE support (although RubyMine) does an awesome job of warning of possible code problems just using code inspection).<p>I sometimes wish that one programming language would work for all of my requirements but I keep needing: scripting languages for quickly getting stuff done; practical languages like Clojure and Java, and type strict languages like Haskell (that I would like to use more, but development takes longer).<p>Looking ahead a few years, the ideal for me would be a loose scripting language that had awesome static analysis tools. So, for example, I would get the safety of Haskell when hacking in Ruby.
pixelmonkeyover 9 years ago
It&#x27;s cool that PyCharm added support for this -- the point of the typing module and the type hinting PEP is for IDEs to adopt it for linting purposes.<p>For those of you using vim, emacs, and the standard UNIX editing toolchain, the mypy linter provides command-line support. This blog post from April 2015 describes the first version of mypy that includes support for the official typing library.<p><a href="http:&#x2F;&#x2F;mypy-lang.blogspot.co.uk&#x2F;2015&#x2F;04&#x2F;mypy-02-released.html" rel="nofollow">http:&#x2F;&#x2F;mypy-lang.blogspot.co.uk&#x2F;2015&#x2F;04&#x2F;mypy-02-released.htm...</a>
graffiticiover 9 years ago
So how do we get some of these benefits if we don&#x27;t use PyCharm, but use Vim? Are there standalone tools, or VIM plugins?
评论 #10626932 未加载
eccstartupover 9 years ago
Can this be fixed?<p><a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;25588642&#x2F;pycharm-false-syntax-error-using-turtle" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;25588642&#x2F;pycharm-false-sy...</a>
Klasiasterover 9 years ago
Has someone tried GNOME Builder? I found it quite good for C, but the Python mode of PyCharm is still superior regarding search and introspection, yet it is not Free Software…
ZLeviathanover 9 years ago
Finally! without the additional type information, it&#x27;s almost impossible to do any meaningful refactoring...