Skip to content

Missing quotations around forward references #3334

Closed

Description

@jakebailey

I'm in progress updating the Microsoft language server's copy of the typeshed repo in preparation for 3.8, and some type annotations we had been testing have broken on moving up to the latest master of typeshed (microsoft/python-language-server#1654).

Specifically #3191 removed some quotations around forward references, which broke some testing we had done to verify handling of Path's division overloads.

As far as I can tell from PEP 484, forward references should be using strings for types rather than actually referencing them (https://www.python.org/dev/peps/pep-0484/#forward-references), and our type system needs this assumption to be able to evaluate things correctly. In our case, replacing:

_P = TypeVar('_P', bound=PurePath)

with:

_P = TypeVar('_P', bound='PurePath')

Means we can process the stub, and this seems more reasonable from the point of "executing" the stub (if stubs could be run as-is), since PurePath has not yet been defined.

Should these forward references have been unquoted? Or has there been some change to the spec that isn't documented in the PEP?

Activity

  1. gvanrossum commented on Oct 9, 2019

    @gvanrossum
    Member

    Actually there is a special exception for stub files -- forwards references in those do not have to be enclosed in quotes. Stubs are not meant to be executed, so the reason for the quotes is not there.

  2. jakebailey commented on Oct 9, 2019

    @jakebailey
    ContributorAuthor

    Is there a listing of all of the differences that stub files may have from regular code that uses typing? I didn't see that stub files had an exception like this in the PEP 484 docs.

    The pathlib example is tricky because the bound created for _P refers back again to _P (so at least at the moment, I think we end up not having _P defined when it's needed later on). Likely fixable on our end, just tricky since we hadn't considered it.

  3. jakebailey commented on Oct 9, 2019

    @jakebailey
    ContributorAuthor

    I'll likely close this since I think that it's something for us to fix, but knowing where to find some info on the stub exceptions would be nice to have. 😃

  4. JelleZijlstra commented on Oct 9, 2019

    @JelleZijlstra
    Member

    We're (slowly) working on documenting this sort of thing at https://github.com/srittau/type-stub-pep.

  5. jakebailey commented on Oct 11, 2019

    @jakebailey
    ContributorAuthor

    In the meantime, it'd be helpful for this repo's README to not state that stubs can be interpreted by Python 3 (https://github.com/python/typeshed#format), and perhaps point to the proposed new specs with a note that the stubs here aren't following PEP 484 exactly. The way stubs are structured differing from typical Python is a bit of a bummer for analyzers which relied on that being the case and were just following what was written in PEP 484. 🙁

  6. superbobry commented on Sep 30, 2020

    @superbobry
    Contributor

    Hi @JelleZijlstra, out of curiosity has there been any progress on the type stubs PEP since?

  7. srittau commented on Oct 1, 2020

    @srittau
    Collaborator

    It's still on my agenda, but nothing new so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions