[Python-Dev] typeshed for 3rd party packages

Guido van Rossum guido at python.org
Wed Apr 22 19:23:13 CEST 2015


On Wed, Apr 22, 2015 at 9:12 AM, Skip Montanaro <skip.montanaro at gmail.com>
wrote:

>
> On Wed, Apr 22, 2015 at 10:43 AM, Guido van Rossum <guido at python.org>
> wrote:
>
>> For Requests, it looks like it may be better not to have stubs at all.
>
>
> Can you expand on this? Why would Requests be any different than any other
> module/package?
>

Did you see the crazy union that Cory came up with for one of the
parameters of get() in another thread? Requests assumes duck typing for
most of its arguments *and* it handles different forms of many arguments
(e.g. you can specify an iterable or a mapping).

Requests is different for a number of reasons; it has evolved for years to
support many different use cases with a few methods, so it is using every
trick in the book from dynamic typing.

Type checking (using the current state of the tools) is probably more
useful for "business logic" code than for "library" code. We'll iterate
over the next few Python versions (and even while Python 3.5 is out we can
tweak typing.py because it's provisional in the PEP 411 sense) and
eventually it may be possible to provide stubs for Requests. But since PEP
484 doesn't address duck typing it's simply too early. (As I said
elsewhere, duck typing is an important next step, but we need PEP 484 as
the foundation first).


>
> As for versioning, I think stub files would absolutely have to declare the
> appropriate version(s) to which they apply (probably via embedded
> directives), so type checkers can ignore them when necessary. That also
> means that type checkers must be able to figure out the version of the
> package used by the application being analyzed.
>
> Not sure I'm being too clear, so I will provide an example. I have app
> "myapp" which imports module "yourmod" v 1.2.7. The yourmod author hasn't
> yet provided type annotations, so someone else contributed a stub to the
> typeshed. Time passes and a new version of "yourmod" comes out, v 2.0.0.
> (Semantic versioning tells us the API has changed in an incompatible way
> because of the major version bump.) I decide I need some of its new
> features and update "myapp". There is no new stub file in the typeshed yet.
> When I run my fancy type checker (someone suggested I will shortly have 50
> to choose from!), it needs to recognize that the stub no longer matches the
> version of "yourmod" I am using, and must ignore it.
>
> Does that suggest the typeshed needs some sort of structure which allows
> all versions of stubs for the same package to be gathered together?
>
> My apologies if I'm following along way behind the curve.
>

No, I think you can start filing (or adding your view to) issues with the
typeshed tracker: https://github.com/JukkaL/typeshed/issues

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150422/27420494/attachment.html>


More information about the Python-Dev mailing list