Live data from Hacker News

Python developers are embracing type hints

pyrefly.org

261–270 of 581 posts

Re: Python developers are embracing type hints

#261
post #245

Earlier quoted context omitted.

The RDF structure is a graph of typed instances of typed objects, serializable as text. Exchanging RDF, more precisely its [more readable] "RDF/turtle" variant, is probably what will eventually come to the market somehow. Each object of a RDF structure has a global unique identifier, is typed, maintains typed links with other objects, have typed values.

That's a circular argument. What serialization format would you recommend? JSON?

Turtle directly.

JSON forces you to fit your graph of data into a tree structure, that is poorly capturing the cardinalities of the original graph.

Plus of course, the concept of object type is not existing in JSON.

Re: Python developers are embracing type hints

#262
post #25

The thing that finally got me on board with optional type hints in Python was realizing that they're mainly valuable as documentation. But it's really valuable documentation! Knowing what types are expected and returned just by looking at a function signature is super useful.

> The thing that finally got me on board with optional type hints in Python was realizing that they're mainly valuable as documentation. > But it's really valuable documentation! Knowing what types are expected and returned just by looking at a function signature is super useful. So ... you didn't have this realisation prior to using Python type hints? Not from any other language you used prior to Python?

I didn't. I've been mainly a Python, PHP and JavaScript programmer for ~25 years and my experience with typed languages was mostly pre-type-inference Java which felt wildly less productive than my main languages.

Re: Python developers are embracing type hints

#263

Earlier quoted context omitted.

I would say mypy is better than nothing but it still misses things sometimes, and makes some signatures difficult or impossible to write. I use it anyway, but patched-on static typing (Erlang, Clojure, and Racket also have it) seems like a compromise from the get-go. I'd rather have the type system designed into the language.

Mypy is trash but Pyright is very good.

I went from mypy to pyright to basedpyright and just started checking out pyrefly (the OP), and it's very promising. It's written in Rust so it's very efficient.

Re: Python developers are embracing type hints

#264
post #261

Earlier quoted context omitted.

That's a circular argument. What serialization format would you recommend? JSON?

Turtle directly. JSON forces you to fit your graph of data into a tree structure, that is poorly capturing the cardinalities of the original graph. Plus of course, the concept of object type is not existing in JSON.

Thank you, I did not realize that RDF has its own serialization format. I'm reading about it now.

Re: Python developers are embracing type hints

#265

I know I am going to be in the minority, but I don't understand why we can't let Python be Python. Static typing is great, and there are already other statically typed languages for all your needs. Why not use them? Well, at least it doesn't create two incompatible Pythons like async and (I assume) free threading.

Because Python has a lot of things it's great at (numeric stuff, ML, computer vision, scripting), and with types you can actually rely on it to work. It's the best of both worlds.

Re: Python developers are embracing type hints

#268
post #23

Or you could just use a statically typed language and get a much better experience.

Would you? Why? Python has a great experience for a bunch of tasks and with typing you get the developer experience and reliability as well.

> Why?

Python’s 3 traditional weak spots, which almost all statically-typed languages do better: performance, parallelism and deployment.

Re: Python developers are embracing type hints

#269
post #211
post #138

Earlier quoted context omitted.

Here we are because: * Types are expensive and dont tend to pay off on spikey/experimental/MVP code, most of which gets thrown away. * Types are incredibly valuable on hardened production code. * Most good production code started out spikey, experimental or as an MVP and transitioned . And so here we are with gradual typing because "throwing away all the code and rewriting it to be "perfect" in another language" has…

> * Types are expensive and dont tend to pay off on spikey/experimental/MVP code, most of which gets thrown away. This is what people say, but I don't think it's correct. What is correct is that say, ten to twenty years ago, all the statically typed languages had other unacceptable drawbacks and "types bad" became a shorthand for these issues. I'm talking about C (nonstarter for obvious reasons), C++ (a huge mess, fo…

> Nowadays we have Go and Rust, both of which are pretty easy to iterate in (for different reasons).

It's common for Rust to become very difficult to iterate in.

https://news.ycombinator.com/item?id=40172033

Re: Python developers are embracing type hints

#270
post #200

I'm always surprised when people suggest using a different language if you want typing in Python. Python's (second?) largest appeal is probably its extensive ecosystem. Whenever people suggest just changing languages, I wonder if they work in isolation, without the need for certain packages or co-worker proficiency in that language.

I think people usually say it for a different reason. Types are not enforced. You can annotate your code that looks correct to the type checker, but the actual data flow at runtime can be with different types. And it happens quite often in large codebases. Sometimes external dependencies report wrong types, e.g., a tuple instead of a list. It's easy to make such a mistake when a library is written in a compiled langu…

To be pedantic compiled languages only check types at compile time as well. If you have a C library that takes void* then it can easily go wrong at runtime.
Post reply on HN