Python’s “Type Hints” are a bit of a disappointment to me

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
coderabbit.ai
featured
Nutrient - The #1 PDF SDK Library
Bad PDFs = bad UX. Slow load times, broken annotations, clunky UX frustrates users. Nutrient’s PDF SDKs gives seamless document experiences, fast rendering, annotations, real-time collaboration, 100+ features. Used by 10K+ devs, serving ~half a billion users worldwide. Explore the SDK for free.
nutrient.io
featured
  1. pyright

    Static Type Checker for Python

    MyPy isn’t the only checker of course, there’s also Microsoft’s Pyright, among others. Pyright is fast and natively integrated in Microsoft’s Pylance VSCode extension, so these days I use Pyright’s type checking in real time even when I can’t be bothered to set up MyPy (no difficult, just not important for, say, <1000 line scripts).

    https://github.com/microsoft/pyright

    https://marketplace.visualstudio.com/items?itemName=ms-pytho...

  2. CodeRabbit

    CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.

    CodeRabbit logo
  3. mypy

    Optional static typing for Python

    It reminds me of this 5 year old bug in mypy: "int is not a Number?" [1].

    [1]: https://github.com/python/mypy/issues/3186

  4. beartype

    Unbearably fast near-real-time hybrid runtime-static type-checking in pure Python.

  5. returnn

    The RWTH extensible training framework for universal recurrent neural networks

    > warnings of IDEs are simple to ignore

    This is unusual. In my experience, of codebases I have worked with or have seen, when there are type hints, there are almost all perfectly correct.

    Also, you can setup the CI to check also for IDE warnings. For example, we use this script for PyCharm: https://github.com/rwth-i6/returnn/blob/master/tests/pycharm...

    The test for PyCharm inspections only passes when there are no warnings.

    Although, I have to admit, we explicitly exclude type warnings because here we have a couple of false positives. So in this respect, it actually agrees with the article.

    But then we also do code review and there we are strict about having it all correct.

    Yes, I see the argument of the article that the typing in Python is not perfect and you can easily fool it if you want, so you cannot 100% trust the types. But given good standard practice, it will only rarely happen that the type is not as expected and typing helps a lot. And IDE type warnings, or mypy checks still are useful tools and catch bugs for you, just not maybe 100% of all typing bugs but still maybe 80% of them or so.

    > Isn’t it better to detect at least some errors than to detect none at all?

  6. Nim

    Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).

    > What I want is this: Some language that’s as easy to use as Python and it should be compiled and with good static typing...

    Well, there's always Nim. [0]

    > ...but it should also not be compiled because then it wouldn’t be as easy to use as Python anymore. Whoops?

    Eh, there's Nimscript? [1]

    0. https://nim-lang.org/

  7. cinder

    Cinder is Meta's internal performance-oriented production version of CPython. (by facebookincubator)

    This article captures a lot of the rationale behind why we're building Static Python within Cinder: https://github.com/facebookincubator/cinder#static-python

  8. enforce

    Python 3.5+ runtime type checking for integration testing and data validation

  9. Nutrient

    Nutrient - The #1 PDF SDK Library. Bad PDFs = bad UX. Slow load times, broken annotations, clunky UX frustrates users. Nutrient’s PDF SDKs gives seamless document experiences, fast rendering, annotations, real-time collaboration, 100+ features. Used by 10K+ devs, serving ~half a billion users worldwide. Explore the SDK for free.

    Nutrient logo
  10. pydantic

    Data validation using Python type hints

  11. typeguard

    Run-time type checker for Python

  12. fastapi

    FastAPI framework, high performance, easy to learn, fast to code, ready for production

  13. typeshed

    Collection of library stubs for Python, with static types

    https://github.com/python/typeshed also provides community maintained stub packages for packages that are lacking upstream type hints

  14. languages-that-compile-to-python

    List of languages that compile to python

    The flawed nature of JS, yet remaining the only one supported by browsers, has indeed created a unique environment where many nice languages have appeared that compile to JS. Besides TypeScript there's Elm, ReasonML, ClojureScript, and many more.

    There are a some competing languages for the Python runtime as well: https://github.com/vindarel/languages-that-compile-to-python

  15. urllib3

    urllib3 is a user-friendly HTTP client library for Python

    (I've chopped it down a bit to emphasise the important bits)

    But then I looked at upstream and I notice they've added type annotations, which do greatly improve things:

    https://github.com/urllib3/urllib3/blob/e16beb210c03c6f5ce4e...

        def _new_conn(self) -> socket.socket:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Astral – "We're building a new static type checker for Python"

    17 projects | news.ycombinator.com | 29 Jan 2025
  • Python Meta Circular Interpreter (2019)

    3 projects | news.ycombinator.com | 18 Dec 2024
  • Python type hints may not be not for me in practice

    8 projects | news.ycombinator.com | 27 Nov 2024
  • Abstract Interpretation in the Toy Optimizer

    1 project | news.ycombinator.com | 27 Jul 2024
  • utype VS pydantic - a user suggested alternative

    2 projects | 15 Feb 2024

Did you know that Python is
the 2nd most popular programming language
based on number of references?