A static type analyzer for Python code
Home
User guide
Developer guide
Error classes
FAQ
Typing FAQ
Supported features
Mailing list
File a bug
View the Project on GitHub google/pytype
Hosted on GitHub Pages — Theme by orderedlist
This page lists the Python versions and features supported by the latest version of pytype.
Version | Analyzes | Runs In | Issue |
---|---|---|---|
2.7 | 2021.08.03 | 2020.04.01 | #545 |
3.5 | 2021.09.09 | 2020.10.08 | #677 |
3.6 | 2022.01.05 | 2022.01.05 | |
3.7 | ✅ | ✅ | |
3.8 | ✅ | ✅ | |
3.9 | ✅ | ✅ | |
3.10 | ✅ | ✅ | |
3.11 | ❌ | ❌ | #1308 |
Note: pytype supports all language and stdlib features in its supported versions unless noted otherwise. This section lists features that are difficult to type for which pytype has or intends to add custom support.
Feature | Supports | Issues |
---|---|---|
Control Flow Analysis (“Type Narrowing”) | ✅ | |
collections.namedtuple | ✅ | |
Dataclasses | ✅ | |
Enums | ✅ | Requires --use-enum-overlay flag externally |
This section describes notable non-standard and experimental features supported by pytype.
Note: This is not and does not endeavor to be an exhaustive list of the ways in which pytype differs from other Python type checkers. See the Pytype Typing FAQ for more on that topic.
Pytype forbids str
from matching an iterable of str
s, in order to catch
a common accidental string iteration bug
(FAQ entry).
Pytype allows ...
as a top-level annotation. When used this way, ...
means “inferred type” (feature request and discussion).
For example, when you use ...
as the annotation for a function’s return
type, the type will be inferred from the function body:
def f() -> ...: # return type inferred as `int`
return 0
For a variable annotation, the type will be inferred from the assignment:
_X: ... = 0 # type of `_X` inferred as `int`
Note: pytype does not guarantee any particular inference strategy. Types
annotated as ...
may even be inferred as Any
, effectively locally
disabling type analysis.
pytype_extensions
: The pytype_extensions
namespace contains many useful
extensions, mostly user-contributed. The best way to learn about them is to
read the inline documentation.
Pytype allows type-annotated variables to be assigned to None
or ...
without including the relevant type in the type annotation. For example, x:
str = None
and x: str = ...
are allowed. This makes it easier to
type-annotate code that uses None
or ...
to indicate an unset value.
Note: This section does not list all third-party libraries that pytype supports, only the ones that are difficult to type for which pytype has or intends to add custom support.
Feature | Supports | Issues |
---|---|---|
Attrs | ✅ | |
Chex | 🟡 | Google-internal |
Flax | 🟡 | Google-internal |
Numpy | 🟡 | Minimal type stub |
Tensorflow | 🟡 | Minimal, Google-internal |