Skip to content

Commit

Permalink
At least mention pytype
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Oct 14, 2019
1 parent 8cd3054 commit 3432df5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Attributes that only carry a class annotation do not have that object so trying

Please note that types -- however added -- are *only metadata* that can be queried from the class and they aren't used for anything out of the box!

In practice, their biggest usefulness shows in combination with mypy.
In practice, their biggest usefulness shows in combination with mypy_ or pytype_ that both have dedicated support for ``attrs`` classes.


mypy
----

While having a nice syntax for type metadata is great, it's even greater that `mypy <http://mypy-lang.org>`_ as of 0.570 ships with a dedicated ``attrs`` plugin which allows you to statically check your code.
While having a nice syntax for type metadata is great, it's even greater that mypy_ as of 0.570 ships with a dedicated ``attrs`` plugin which allows you to statically check your code.

Imagine you add another line that tries to instantiate the defined class using ``SomeClass("23")``.
Mypy will catch that error for you:
Expand All @@ -68,3 +68,7 @@ To mypy, this code is equivalent to the one above:
The addition of static types is certainly one of the most exciting features in the Python ecosystem and helps you writing *correct* and *verified self-documenting* code.

If you don't know where to start, Carl Meyer gave a great talk on `Type-checked Python in the Real World <https://www.youtube.com/watch?v=pMgmKJyWKn8>`_ at PyCon US 2018 that will help you to get started in no time.


.. _mypy: http://mypy-lang.org
.. _pytype: https://google.github.io/pytype/

0 comments on commit 3432df5

Please sign in to comment.