News for hackers. Stuff that matters.
Re:Python's Type Checking Renaissance by stereo on Tuesday January 26, 2021 @11:05AM (#25917365)
For those who have never used type checking in Python, what's a good introduction?
Re:Python's Type Checking Renaissance by aodin on Tuesday January 26, 2021 @11:17AM (#25917537)
For the actual type annotations themselves, the official docs are great: https://docs.python.org/3/library/typing.html

Know that the signatures vary with version, so select the correct one.

To check these annotations, you'll need a third-party type checker somewhere in your build process. I use pylance with VS Code, as it can detect errors as I type: https://marketplace.visualstudio.com/items?itemName=ms-pytho...

Re:Python's Type Checking Renaissance by tgb on Tuesday January 26, 2021 @11:42AM (#25917904)
This doesn't seem like an ideal introduction. I don't think it actually covers type checking at all (besides the note at the top) since that's relegated to third parties.
Re:Python's Type Checking Renaissance by ThePadawan on Tuesday January 26, 2021 @11:59AM (#25918185)
To learn how to use it, I would recommend setting up your IDE (I recommend VS Code) to use mypy.

Then just open a small script you know well, let's say less than 200 lines, and check what "missing" type annotations mypy complains about.

For most cases, the IDE will be able to tell you what it recommends, and from then you can start reading the docs for specific types for a deeper dive.

Re:Python's Type Checking Renaissance by dharbin on Tuesday January 26, 2021 @08:12PM (#25923047)
Pylance is much faster and can index a large virtualenv without issue, IMO
Re:Python's Type Checking Renaissance by high_density on Tuesday January 26, 2021 @11:16AM (#25917530)
read mypy docs, but use google's pytype...

pylance is much stricter, but it seems to have a lot of false-(+)s

from what I've used, the implementation varies wildly...

Re:Python's Type Checking Renaissance by mshekow on Tuesday January 26, 2021 @04:08PM (#25921075)
You may also find my introduction to Python type hints helpful, see https://www.augmentedmind.de/2020/10/11/static-python-type-h...
Re:Python's Type Checking Renaissance by Geminidog on Wednesday January 27, 2021 @01:25AM (#25924962)
Sounds like you've never dealt with a type checking language in general. I recommend using a language that forces you to do type checking like haskell. Haskell is super hard so just use it until you see the light and understand why typing is better.

I would say get good enough with haskell to write a 2 human player tic-tac-toe game by following some online tutorials. Then you'll be able to pick up types in python like it was nothing.

Otherwise if you have used a type checked language... Python types are really straight forward. I never needed a tutorial. Whenever I needed a feature (such as type variables) I would look it up via google.

Anyway, I don't actually know if you've ever played with a type checked language but I'm assuming you haven't because python type checking is pretty easy to pick up without a tutorial based resource if you have had prior experience in other languages.