Skip to content

Optional typing import #3216

@llchan

Description

@llchan

I have some PY2+PY3 code that I'm adding mypy type annotations to, but the PY2 runtime environment does not have the typing backport module. The current workaround is to put a try/except around the typing import, but that looks a bit ugly, and even if the environment did have it, or if I were running in PY3, I dont know that I want that imported at runtime.

Can we support some sort of comment-based directive at the top of the file that mypy can parse?

Apologies if this has already been asked, I tried searching but there is a lot to sift through.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions