<story><title>Python’s “type hints” are a bit of a disappointment to me</title><url>https://www.uninformativ.de/blog/postings/2022-04-21/0/POSTING-en.html</url></story><parent_chain><item><author>mountainriver</author><text>Not typing is kinda a crazy way to write programs when you think about it. It can be beneficial in certain niche use cases like data science where code is always terrible. For everything else, types are a huge boon for the developer and everyone consuming their work</text></item><item><author>linsomniac</author><text>Honestly, I&amp;#x27;ve recently written a few 300-500 line programs in Python using type hints and I&amp;#x27;m never going back.  And I&amp;#x27;m not even using mypy often, if ever.&lt;p&gt;My editor now has a fairly deep understanding of my code, and can tell me of all sorts of surprising errors I&amp;#x27;m making before I run the code.  There have been a few times where I found an error, went into the editor and saw I had missed a error message about that line.  Shout out: Using LunarVim with LSP and TreeSitter.&lt;p&gt;The other thing I&amp;#x27;m enjoying is that libraries can use them to make things happen more automatically.  I believe it was Typer (the CLI argument parsing library) where if you declare an argument to a function as &amp;quot;files: List[Path]&amp;quot;, it understands that the argument will take one or more files, or &amp;quot;-&amp;quot; to mean stdin.  If you just say &amp;quot;file: Path&amp;quot;, it understands it is a singular file.&lt;p&gt;I was curious about type hints when they first came out, wasn&amp;#x27;t really expecting to use them but they seemed cool, but now I&amp;#x27;m totally sold.</text></item></parent_chain><comment><author>waitlist</author><text>I think data science is a perfect example in favor of types -- the code is often terrible &lt;i&gt;because&lt;/i&gt; of the lack of typing. Pandas has notoriously poor developer ergonomics, and I recall painfully poring over type errors across the board -- lists, dataframes, numpy arrays, etc. are all iterables, so they can be interchanged in some contexts, but not in others.&lt;p&gt;Had I had MyPy back when I was working in data science, I would&amp;#x27;ve saved countless hours and headaches.</text></comment>
<story><title>Python’s “type hints” are a bit of a disappointment to me</title><url>https://www.uninformativ.de/blog/postings/2022-04-21/0/POSTING-en.html</url></story><parent_chain><item><author>mountainriver</author><text>Not typing is kinda a crazy way to write programs when you think about it. It can be beneficial in certain niche use cases like data science where code is always terrible. For everything else, types are a huge boon for the developer and everyone consuming their work</text></item><item><author>linsomniac</author><text>Honestly, I&amp;#x27;ve recently written a few 300-500 line programs in Python using type hints and I&amp;#x27;m never going back.  And I&amp;#x27;m not even using mypy often, if ever.&lt;p&gt;My editor now has a fairly deep understanding of my code, and can tell me of all sorts of surprising errors I&amp;#x27;m making before I run the code.  There have been a few times where I found an error, went into the editor and saw I had missed a error message about that line.  Shout out: Using LunarVim with LSP and TreeSitter.&lt;p&gt;The other thing I&amp;#x27;m enjoying is that libraries can use them to make things happen more automatically.  I believe it was Typer (the CLI argument parsing library) where if you declare an argument to a function as &amp;quot;files: List[Path]&amp;quot;, it understands that the argument will take one or more files, or &amp;quot;-&amp;quot; to mean stdin.  If you just say &amp;quot;file: Path&amp;quot;, it understands it is a singular file.&lt;p&gt;I was curious about type hints when they first came out, wasn&amp;#x27;t really expecting to use them but they seemed cool, but now I&amp;#x27;m totally sold.</text></item></parent_chain><comment><author>bayesian_horse</author><text>Have you tried it? Python has gained most of its popularity before type hints, and I would (wildly) guess 99% of Python programmers don&amp;#x27;t even use type checking at all.&lt;p&gt;Static typing is completely viable and I hear those arguments mostly from those who didn&amp;#x27;t use Python for a long time. The added productivity makes up for a little more debugging while the program is running.&lt;p&gt;I&amp;#x27;d also posit that many Python codebases are somewhat less &amp;quot;untyped&amp;quot; than one might assume. Django for example does a lot in its ORM and Form classes to make sure the right stuff goes in the right slot.</text></comment>