Skip to content

App import appears valid to linters due to TYPE_CHECKING block #6158

@uriyyo

Description

@uriyyo

Overview

App is imported in textual.__init__ only within a TYPE_CHECKING block, but linters and type checkers incorrectly
believe that from textual import App is valid code.

Problem

In /src/textual/__init__.py:

if TYPE_CHECKING:
    from textual.app import App

This causes mypy and other tools to think that App is available for import from the textual module:

from textual import App # This appears valid to linters
$ mypy example.py
Success: no issues found in 1 source file

Expected Behavior

Linters should show an error when trying to import App from textual since it's only available during type checking, not at runtime.

Actual Behavior

Linters incorrectly validate from textual import App as valid code, misleading developers into thinking this import
works when it will fail at runtime.

Impact

Developers may write code that passes linting but fails at runtime due to the misleading import validation.

Fix

#6152

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions