[Python-Dev] static typing of input arguments in signatures (was: Language Summit notes)

Łukasz Langa lukasz at langa.pl
Sun Apr 13 10:11:50 CEST 2014


On Apr 13, 2014, at 12:48 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Stefan Behnel, 12.04.2014 19:11:
> 
> So, what I've learned from seven years of Cython is that static typing in
> signatures is actually less interesting than you might think at first
> sight. It might be ok for documentation purposes, although its verboseness
> makes that also a bit questionable.

You raise a valid point that type hinting a dict instead of a Mapping is
likely to create an overly limiting API. This sort of error is however
quite easy to fix forward.

To counter, we’ve had multiple data points during the summit suggesting
that duck typing is not really that often used in production code. In
other words, after initial prototyping and testing, an API of a callable
gets settled and is later used with a very limited number of types.

Of course, fuzzy terms like “often”, “seldom”, and “limited” suggest
that we don’t have hard data here. That being said, there is a clear
need to improve our ability to lint code, refactor code easier, and
document the contracts better. This has been voiced by various
conference attendees and the consensus is tremendous. Moreover, this
need has been proven by owners of large codebases like Google, Facebook,
and Microsoft by creating optionally typed variants of known dynamic
languages (namely Dart, Hack and TypeScript).

For Python specifically the existence of prototypes like Mypy, obiwan,
or pytypedecl shows that there is growing interest in standardizing this
functionality. Therefore, I'm drafting a PEP for opt-in type hints with
optional checks at runtime and by static analysis. Will post the initial
form in the upcoming days, and then we can go paint that bike shed.

I'm aware that great care here is needed for the outcome to feel
Pythonic and not overwhelming. Don't worry before you get your hands on
the draft, though.

-- 
Best regards,
Łukasz Langa

WWW: http://lukasz.langa.pl/
Twitter: @llanga
IRC: ambv on #python-dev


More information about the Python-Dev mailing list