Skip to content

Support sys.implementation.name as feature switch for stubs #1339

@cdce8p

Description

@cdce8p

Problem

Sometimes, attributes and variables are only defined for a specific implementation.
E.g. I recently saw that PyPy has a sys.pypy_version_info variable.

At the moment, type checkers only support sys.version_info and sys.platform checks AFAIK.1

Idea

Add support for sys.implementation.name2 checks.

import sys

if sys.implementation.name == "pypy":
    pypy_version_info: ...

Footnotes

  1. https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=sys.platform#python-version-and-system-platform-checks

  2. https://peps.python.org/pep-0421/#required-attributes

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions