Live data from Hacker News

Python’s “type hints” are a bit of a disappointment to me

uninformativ.de

501–510 of 597 posts

Re: Python’s “type hints” are a bit of a disappointment to me

#501
post #262

Earlier quoted context omitted.

I don't want to turn Python into a statically typed language. I think there's valid criticism to be made about the flaws of its type hinting (as does the article's author), and I cannot help but compare its usefulness to static type checking. I also cannot choose the language. I'm not in a position to choose languages at my current job; I seldom find myself in that position at any job.

We are going to go back in circles, but as I said in the very first comment: mypy is the tool you want [0]. It won't do everything, but progress has been steady and more and more projects are providing type libraries for it. But given that your response to the mypy recommendation was to complain (it's slow, it doesn't catch everything) then it makes it difficult to acknowledge the "valid criticism"... as in: people a…

> "We are going to go back in circles, but as I said in the very first comment: mypy is the tool you want [0]"

What makes you think I'm not using mypy, or that I didn't read the article you linked to or follow its guidelines (which are very sensible)?

In your mind, is it the only possibility when someone criticizes a tool that they are "using it wrong" (to paraphrase Steve Jobs)? No other possible reason?

> "But given that your response to the mypy recommendation was to complain (it's slow, it doesn't catch everything) then it makes it difficult to acknowledge the "valid criticism"... as in: people are working on it, what else do you want?"

Given that I didn't say or imply that I don't believe there are people working on improving mypy and Python type hints, "what I want" is merely to support the article's assertion that the current version of type hints Python provides is confusing and not very good.

Please, for the love of all that is holy, don't recommend to me again that I switch to a different language. That's not how this works.

Re: Python’s “type hints” are a bit of a disappointment to me

#502
post #73
post #70

Earlier quoted context omitted.

as a reminder for yourself/others who need to read/maintain your code? (I am often reminded of my perl days, where something I thought idiomatic 3 days ago, is now completely incomprehensible when I just want to make a minor change)

So is it simply a standardized comment then? I will have a really bad time convincing my team mates, if that's the case. It's especially bad because, like any comment, it can say one thing but the code may do something different (actually happened to me).

> So is it simply a standardized comment then? I will have a really bad time convincing my team mates, if that's the case.

If your team doesn't understand the value of things that are essentially standardized comments exposed through the IDE (even if it wasn't for validation, which is also available with IDE integration), you have very bad teammates.

Re: Python’s “type hints” are a bit of a disappointment to me

#503
post #149

Earlier quoted context omitted.

> That's what drives me crazy. I come from the statically typed world. This bit of Python's philosophy really clashes with my world view. That’s the kind of the culture shock you get learning dynamic type languages with a static type pov. Type hinting is not really the problem here, but can seem that way because it makes dynamically typed code too superficially similar that it enters the uncanny valley if you treat i…

Agreed, but it also clashes with the world view that brought us Typescript, which I also find better than Python's type hinting. In addition, it makes it harder for me to argue in favor of type annotations with my coworkers. My coworkers come from neither world, static or dynamic; they are learning the ropes. And they just can't see the point. I'm confident I would convince them were this a statically typed language,…

The TypeScript comparison is on an entirely different axis though, the compiled interpreted one. One of the reasons languages go with the type hinting route is actually to avoid a separate compilation step like TypeScript. That may be totally fine for you (again coming from a statically typed language where this is more or less required), but it’s a hill many are willing to die on. It’s all tradeoffs and design decisions.

Re: Python’s “type hints” are a bit of a disappointment to me

#504
post #138
post #128

Earlier quoted context omitted.

it's a comment which can trigger an action (if you run mypy). So, unlike a comment, which does nothing, if you run mypy and get some warnings, you can then do something about it (whether it's just # type: ignore or you realise you made a mistake with allocating to variable new_value versus newvalue/new_valu/etc) (btw, in case someone objects, some comments DO do something, e.g. golang's godoc examples)

Now I'm confused because the root comment I was replying to asserted that type hints are for documenting, not for checking. If they are for checking, then my other opinion stands: that they are not very good at it (compared to my experience with statically typed languages, even with Typescript!).

They are for documenting and checking. Obviously, if static typing is your only concern, you wouldn't have picked Python to start with, but if you did have a reason to pick Python, you can get a large subset of the value of static typing for correctness and dev-tine information via Python’s support for type hints and the typecheckers (mypy keeps getting pointed to, but it's not the only one) that support it.

Re: Python’s “type hints” are a bit of a disappointment to me

#505

Earlier quoted context omitted.

JS is popular because it's literally the only language web browsers support. Python is popular because it's very beginner oriented, so it's the first language a lot of people learn. It's modern BASIC. Neither of those things mean that writing dynamically typed code is a good idea. The idea that you can write dynamically typed code faster isn't even true once you get past a couple of hundred lines.

This concept of "programer is generally dumb, so languages must have features to prevent them from making mistakes", with strong typing falling under those features, is solely an academic exercise that is taught in academia, and perpetuated by people who just wanna fit the mold in FAANG and other big players. And Python being popular because its basic/beginner oriented is a laughable statement. http://highscalability…

> This concept of "programer is generally dumb, so languages must have features to prevent them from making mistakes", with strong typing falling under those features, is solely an academic exercise that is taught in academia, and perpetuated by people who just wanna fit the mold in FAANG and other big players.

Ah the classic "I don't make mistakes" delusion.

Re: Python’s “type hints” are a bit of a disappointment to me

#506
post #2

I haven't used python's type hints much yet but I used TypeScript a bunch about a year ago and I have the exact same complaints. Most of the benefit of types goes away unless _everything_ is typed... my libraries, the libraries my libraries use, etc. I should be able to jump around in and out of library code following types and usages thereof in my IDE, making conclusions that are accurate based on what the types say…

I think Typescript nowadays has reached critical mass where most packages at least have a @types/* definition. I can't remember the last time I had to use a package that didn't provide types. I had the types be wrong one time though.

Re: Python’s “type hints” are a bit of a disappointment to me

#507
post #461

Earlier quoted context omitted.

How did you get from type hints to black, not to mention poetry? Seems like you're just complaining about there being a mature ecosystem around Python, and the implicit expectation to use it.

And here I thought my explanation at the bottom covered this. Let's try again: Python has become a mess. It is no longer a simple productive language to get into like it used to be. Now, you are expected to buy into it's ecosystem, like it is C# or Java. Well, it is not. It's Python and I am truly sad they are killing it with thousand cuts.

Yes, it's getting more complicated. Yes, there's a whole ecosystem being built around it, and the line between language and ecosystem is blurry. And indeed, there's a hidden expectation for any Python developer to buy into the whole ecosystem.

But that's just a symptom of a mature programming language that's used in a variety of complicated scenarios. You don't have to do it all, and no-one is forcing you. You can always write your one-off script without black, flake8, type hinting, or anything of the sort. If it's just your script then no-one will even know.

On the other hand, if you want your code to be part of the larger ecosystem, then you're expected to write it in a conformant way (e.g. pep8 formatting). And that's a good thing!

Re: Python’s “type hints” are a bit of a disappointment to me

#508
post #501

Earlier quoted context omitted.

We are going to go back in circles, but as I said in the very first comment: mypy is the tool you want [0]. It won't do everything, but progress has been steady and more and more projects are providing type libraries for it. But given that your response to the mypy recommendation was to complain (it's slow, it doesn't catch everything) then it makes it difficult to acknowledge the "valid criticism"... as in: people a…

> "We are going to go back in circles, but as I said in the very first comment: mypy is the tool you want [0]" What makes you think I'm not using mypy, or that I didn't read the article you linked to or follow its guidelines (which are very sensible)? In your mind, is it the only possibility when someone criticizes a tool that they are "using it wrong" (to paraphrase Steve Jobs)? No other possible reason? > "But give…

> "what I want" is merely to support the article's assertion that the current version of type hints Python provides is confusing and not very good.

What I am having trouble to grasp is: if you understand that Python is not a statically typed language, and if you claim that you do not want to "turn" Python into such, why do you keep conflating type hinting with type checking?

They are two separate things. That is the nature of the game. Do you have criticisms about limitations from mypy, fine, but then you are not talking about issues with type hinting but merely the type checker tool.

Re: Python’s “type hints” are a bit of a disappointment to me

#509
post #446

Adding type hints to Python has increased my productivity by at least a factor of 10. They allow you to reason about code in a local function without having to track back up dozens of call sites to ensure you're getting what you think you're getting. That alone is worth the price of admission. Both when editing code or reviewing someone else's. It's fantastic, particularly in a very large code base. The editor experi…

Why not just use a statically type language? I really don't understand why python is so popular outside of a few specialized areas.

It's basically a lisp with better syntax.

Re: Python’s “type hints” are a bit of a disappointment to me

#510
post #255

While I love the idea behind Python's type hints, they are merely a shadow of the success of TypeScript. Like the author, I've mostly given up on adding type hints in my Python code. I now only use them when I want to help my IDE find autocomplete suggestions. Whereas TypeScript was a game changer for JavaScript. I used to hate JavaScript, but somehow TypeScript has become one of my favourite languages! How has the a…

The fact that we can't have a type for JSON really does make it look like a toy.

Use pydantic then. Then you get type checking and validation for your json blobs.
Post reply on HN