Skip to content

Move type-only imports into TYPE_CHECKING blocks - #208

Merged
FichteFoll merged 3 commits into
SublimeText:masterfrom
rchl:ruff-type-checking-imports
Oct 18, 2026
Merged

FichteFoll merged 3 commits into
SublimeText:masterfrom
rchl:ruff-type-checking-imports

Conversation

@rchl

@rchl rchl commented Oct 18, 2026

Copy link
Copy Markdown
Member

typing_extensions isn't available at runtime in Sublime Text's plugin host, and sublime_lib doesn't declare it as a runtime dependency. So the unconditional from typing_extensions import Self in flags.py and activity_indicator.py could fail with ImportError.

Changes:

  • Enable ruff's flake8-type-checking (TC) rules.
  • Set exempt-modules = ["typing", "sublime"]. Ruff exempts typing_extensions by default, which hides exactly this problem. sublime is always present at runtime, so it stays a plain import.
  • Apply the TC fixes, which move Self, TracebackType, Iterable and Generator behind TYPE_CHECKING. All of them are used only in annotations, and every affected module has from __future__ import annotations.
  • Add typing-extensions to the lint dependency group for type checkers.
  • Bump the sublime-text-stubs lower bound.

ruff check and ruff format --check pass.

rchl added 2 commits October 18, 2026 20:38
`typing_extensions` is not available at runtime in Sublime Text's plugin
host, so importing it unconditionally can fail with ImportError.

- Enable ruff's flake8-type-checking (TC) rules and stop exempting
  `typing_extensions`; exempt `sublime` since it is always available.
- Move annotation-only imports behind `TYPE_CHECKING`.
- Add `typing-extensions` to the lint dependency group for type checkers.
- Bump the `sublime-text-stubs` lower bound.
Comment thread pyproject.toml
@deathaxe

Copy link
Copy Markdown
Member

The little amount of such type only imports doesn't really justify overhead of extra TYPE_CHECKING imports.

@FichteFoll

Copy link
Copy Markdown
Member

I do not understand how a TYPE_CHECKING import can qualify as "overhead" for a module that is practically always loaded (and that we load in sublime_lib anyway). Besides, the main goal to enable the TC lint rules is to avoid such issues in the future.

@deathaxe

Copy link
Copy Markdown
Member

It adds useless noise for just gating single imports.

Comment thread .gitignore
Comment thread pyproject.toml
Comment thread pyproject.toml Outdated
@deathaxe

Copy link
Copy Markdown
Member

There are two justifications for TYPE_CHECKING gates

  1. many type only imports which would cause too much overhead at runtime imports
  2. keeping incompatible typing syntax out of the way for older runtimes.

@FichteFoll

Copy link
Copy Markdown
Member

By the way, we can also remove the typing-extensions dependency from the docs project now for the same reason.

@FichteFoll
FichteFoll merged commit 71be33c into SublimeText:master Oct 18, 2026
1 check passed
@rchl
rchl deleted the ruff-type-checking-imports branch October 18, 2026 19:38
@FichteFoll FichteFoll added this to the 2.2.1 milestone Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants