News for hackers. Stuff that matters.
Re:Python type hints may not be not for me in practice by robjwells on Wednesday November 27, 2024 @04:16AM (#42254383)
Worst of both worlds is right. I came back to a Python project with a couple of critical but untyped dependencies recently after writing mostly Rust, and to clear up a large number of these (particularly “type is partially unknown”) I had the choice between lots of purely type-checking ceremony (`typing.cast`) or going without.
Re:Python type hints may not be not for me in practice by rrr_oh_man on Wednesday November 27, 2024 @05:55AM (#42255004)
What did you end up choosing & why?
Re:Python type hints may not be not for me in practice by robjwells on Wednesday November 27, 2024 @06:17AM (#42255130)
It's only a personal side project and I have a good handle on the untyped modules in question, so in the end I suppressed most of the errors with `# type:ignore` and friends.

I'd reconsider that if I was doing more than the odd bug fix on the project. I still like Python, and started using type hints early, but there's enough added friction to make me question using them in the future.

I imagine on big projects the benefit is clearer.

Re:Python type hints may not be not for me in practice by rrr_oh_man on Wednesday November 27, 2024 @11:13AM (#42257169)
Thanks for sharing!

Asking because I was really, really annoyed by the non-helpfulness of the type hints in practice, contrary to the theory.

Re:Python type hints may not be not for me in practice by gizmo385 on Wednesday November 27, 2024 @09:44AM (#42256476)
The third option here is writing type stubs for the library, which you can sometimes find community versions of as well. They’re not too time consuming to write and generally work well enough to bridge the gap
Re:Python type hints may not be not for me in practice by robjwells on Wednesday November 27, 2024 @11:35AM (#42257348)
Yeah, I think this may be a good option when actively working on a project. Sadly at the moment, it's mostly a case of "I just need to make a couple of bug fixes in this old project, why is my editor shouting at me?"