Live data from Hacker News

Python developers are embracing type hints

pyrefly.org

11–20 of 581 posts

Re: Python developers are embracing type hints

#11

Typescript turned me into a believer but my gosh do python typings feel clumsy and quickly busy up files. I get why, and it’s not exactly realistic, but I wish a lot of it didn’t require an import. Whatever the solution is, it doesn’t include giving up on Python typings.

With the newest Python versions, most of the time I don't need typing imports!

Re: Python developers are embracing type hints

#12
post #5

Type hints are much easier to use nowadays than they were a few years ago, because the agentic tools like Claude Code are very good at converting an existing codebase to using type hints.

The flip side of it is that Claude Code will have a very bad time in a code base with grossly unsatisfiable or conflicting types (where a type checker would fail the project). A human should always first ensure that the types are broadly correct, with or without the assistance of code tools.

I can empathize with the code tools. Sometimes I’ll read Python code and have no idea at first glance if these are type bugs or creative coding by the dev. Python is incredibly flexible. Though I think most of the time you really shouldn’t be using the flexibility.

Re: Python developers are embracing type hints

#13
Type hints in dynamic languages are great, but I wish they came with deeper integration into the language runtime for validation and for optimizer setup.

If I have a function that takes an int, and I write down the requirement, why should a JIT have to learn independently of what I wrote down that the input is an int?

I get that it's this way because of how these languages evolved, but it doesn't have to stay this way.

Re: Python developers are embracing type hints

#16
post #8
post #6

I enforce strong types on all Python code I’m responsible for - and make sure others don’t play fast and loose with dict[str, Any] when they could use a well defined type. Doing otherwise is just asking for prod incidents.

I worked on a project that did this. Drove me absolutely nuts. It's like having all the worst parts of a dynamic language and a static language with none of the benefits. I'd much rather just work in a statically typed language from the start.

What exactly drove you nuts? The python ecosystem is very broad and useful, so it might be suitable for the application (if not, reasonable that you'd be frustrated). With strict mypy/pyright settings and an internal type-everything culture, Python feels statically typed IME.

Re: Python developers are embracing type hints

#17

I recently had to debug someone else's Python code and trying to figure out what variables are was a massive headache, especially coming from C++.

Even c++ feels clunky in terms of types to me. Though that's probably down to me preferring a more complete type system like haskell has

Re: Python developers are embracing type hints

#19
I really love Python for it's expedience, but type hints still feel like they don't belong in the language. They don't seem to come with the benefits of optimisation that you get with static typed languages. As someone who uses C and Julia (and wishes they had time for Rust), introducing solid typing yields better end results at a minimum, or is a requirement at the other end of the scale.

The extra typing clarification in python makes the code harder to read. I liked python because it was easy to do something quickly and without that cognitive overhead. Type hints, and they feel like they're just hints, don't yield enough of a benefit for me to really embrace them yet.

Perhaps that's just because I don't use advanced features of IDEs. But then I am getting old :P

EDIT: also, this massively depends on what you're doing with the language! I don't have huge customer workloads to consider any longer..!

Post reply on HN