spark-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maciej Szymkiewicz <>
Subject [PYTHON] PySpark typing hints
Date Sun, 14 May 2017 21:44:17 GMT
Hi everyone,

For the last few months I've been working on static type annotations for
PySpark. For those of you, who are not familiar with the idea, typing
hints have been introduced by PEP 484
( and further extended with
PEP 526 ( with the main goal
of providing information required for static analysis. Right now there a
few tools which support typing hints, including Mypy
( and PyCharm
Type hints can be added using function annotations
(, Python 3 only), docstrings,
or source independent stub files
( Typing is
optional, gradual and has no runtime impact.

At this moment I've annotated majority of the API, including majority of
pyspark.sql and At this moment project is still rough around
the edges, and may result in both false positive and false negatives,
but I think it become mature enough to be useful in practice.

The current version is compatible only with Python 3, but it is
possible, with some limitations, to backport it to Python 2 (though it
is not on my todo list).

There is a number of possible benefits for PySpark users and developers:

  * Static analysis can detect a number of common mistakes to prevent
    runtime failures. Generic self is still fairly limited, so it is
    more useful with DataFrames, SS and ML than RDD, DStreams or RDD.
  * Annotations can be used for documenting complex signatures
    ( including dependencies on arguments and value
  * Detecting possible bugs in Spark (SPARK-20631) .
  * Showing API inconsistencies.


  * Update the project to reflect Spark 2.2.
  * Refine existing annotations.

If there will be enough interest I am happy to contribute this back to
Spark or submit to Typeshed ( -  this
would require a formal ASF approval, and since Typeshed doesn't provide
versioning, is probably not the best option in our case).

Further inforamtion:

  * - GitHub repository

    - interesting presentation by Marco Bonzanini


View raw message