|
|
Subscribe / Log in / New account

PyCharm and type hints

By Jake Edge
June 8, 2016

Python Language Summit

A mini-theme at this year's Python Language Summit was tools that are using the PEP 484 type hints. In the final session on that theme, Andrey Vlasovskikh, the community lead for the PyCharm IDE, described that tool's support for type hints.

Vlasovskikh started by showing a graph of how many PyCharm users were developing in Python 2 versus Python 3 (presumably gathered using the usage statistics feature). As might be expected, Python 2 use has been steadily declining since 2013, while Python 3 use is rising. Currently, it is roughly 50% Python 3 and 70% Python 2, with 20% using both. What might not be expected, though, is that extending the trend lines shows them crossing in December 2017.

After that interesting tidbit, he switched gears. PyCharm used to have its own type system that is similar to that used in PEP 484. So it was not that difficult for PyCharm to switch to supporting the new type hints. But there are still some parts of the PEP that are not supported yet in PyCharm.

[Andrey Vlasovskikh]

Type-hints support was added to PyCharm in November 2015, but users only started to try the feature in March of this year, so there are no real statistics available yet. There are some problems that the PyCharm team has seen. Some users are confused by the Optional type (which effectively allows None as a valid value in addition to any other types specified) and how it relates to arguments with a default value of None. There is also interest in having type hints available for Python 2.

PyCharm does not support strict Union checks or the Type[C] annotation that will allow a class (or its subclasses) to be specified. It also does not use the annotations from the typeshed repository, yet, due to concerns about incomplete annotations for some modules.

One area needing more work is handling text and binary string types for programs that run on both Python 2 and 3. It is important, Vlasovskikh said, and roughly 20% of PyCharm users are using both versions in their projects. The addition of the Text type, which is an alias for str in Python 3 and unicode in Python 2, is a step in the right direction, but more is needed.

The PyCharm developers have sent proposals to the python-ideas mailing list, but they have not been adopted. One would track ASCII values in the code to check for implicit conversions (which is also discussed in this mypy issue). Another was a proposal to give up on strict text versus binary checking in Python 2 that was rejected. Vlasovskikh planned to work on the problem during the sprints that occur right after PyCon and invited others to join in.


Index entries for this article
ConferencePython Language Summit/2016


to post comments


Copyright © 2016, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds