sublime-text-stubs 1.4200.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sublime_text_stubs-1.4200.0/.gitignore +9 -0
- sublime_text_stubs-1.4200.0/CHANGELOG.md +101 -0
- sublime_text_stubs-1.4200.0/CONTRIBUTING.md +155 -0
- sublime_text_stubs-1.4200.0/LICENSE +22 -0
- sublime_text_stubs-1.4200.0/PKG-INFO +169 -0
- sublime_text_stubs-1.4200.0/README.md +149 -0
- sublime_text_stubs-1.4200.0/pyproject.toml +223 -0
- sublime_text_stubs-1.4200.0/references/LICENSE +21 -0
- sublime_text_stubs-1.4200.0/references/README.md +4 -0
- sublime_text_stubs-1.4200.0/stubs/sublime-stubs/__init__.pyi +3321 -0
- sublime_text_stubs-1.4200.0/stubs/sublime_plugin-stubs/__init__.pyi +1461 -0
- sublime_text_stubs-1.4200.0/stubs/sublime_types-stubs/__init__.pyi +223 -0
- sublime_text_stubs-1.4200.0/tests/typing/check_sublime.py +258 -0
- sublime_text_stubs-1.4200.0/tests/typing/check_sublime_plugin.py +248 -0
- sublime_text_stubs-1.4200.0/tools/.python-version +1 -0
- sublime_text_stubs-1.4200.0/tools/generate_stubs.py +1224 -0
- sublime_text_stubs-1.4200.0/tools/pyproject.toml +69 -0
- sublime_text_stubs-1.4200.0/tools/stub_overrides.py +736 -0
- sublime_text_stubs-1.4200.0/tools/uv.lock +75 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
Versions follow `1.${st_build_version}.${patch}`,
|
|
7
|
+
not semantic versioning; see the README.
|
|
8
|
+
|
|
9
|
+
## 1.4200.0
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The project is now licensed under the MIT License.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `sublime_plugin.find_view_event_listener()`,
|
|
18
|
+
which returns the instance of the given `ViewEventListener` class attached to a view.
|
|
19
|
+
It is not part of the documented API
|
|
20
|
+
and may change without notice.
|
|
21
|
+
|
|
22
|
+
## 1.4200.0b2
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Stub-only `TypedDict`s for the dictionaries the API returns or accepts.
|
|
27
|
+
They have no counterpart at runtime,
|
|
28
|
+
so import them under `if TYPE_CHECKING:`.
|
|
29
|
+
- `UIInfo` for `sublime.ui_info()`,
|
|
30
|
+
including the `color_scheme.palette` colors.
|
|
31
|
+
- `ScopeStyle` for `View.style_for_scope()`,
|
|
32
|
+
with the "(only if set)" keys marked `NotRequired`
|
|
33
|
+
and `source_line`/`source_file` typed as `int`/`str`,
|
|
34
|
+
which is what the runtime returns
|
|
35
|
+
rather than what the upstream docstring claims.
|
|
36
|
+
- `MacroStep` for the entries of `sublime.get_macro()`.
|
|
37
|
+
- `WindowLayout` for `Window.layout()`, `Window.get_layout()` and `Window.set_layout()`.
|
|
38
|
+
- `WindowVariables` for `Window.extract_variables()`, all keys optional.
|
|
39
|
+
`sublime.expand_variables()` now takes `dict[str, str] | WindowVariables`,
|
|
40
|
+
so the round trip its docstring recommends keeps type-checking.
|
|
41
|
+
- `FontOptions` for the default and the callback argument of `choose_font_dialog()`,
|
|
42
|
+
both keys optional.
|
|
43
|
+
- `ValueLike` and `CommandArgsLike` in `sublime_types`,
|
|
44
|
+
accepted wherever a plugin passes a value *into* Sublime Text.
|
|
45
|
+
`Value`'s containers, `list[Value]` and `dict[str, Value]`, are invariant,
|
|
46
|
+
so a `List[str]` or `Dict[str, str]` could not be passed where a `Value` was expected;
|
|
47
|
+
`ValueLike` uses the covariant `Sequence` and `Mapping` protocols instead.
|
|
48
|
+
As a consequence it also admits a `Mapping` that is not a `dict`,
|
|
49
|
+
which type-checks but is rejected at runtime,
|
|
50
|
+
and it does not model that whatever is passed in
|
|
51
|
+
comes back as a plain `list` or `dict`.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- `ListInputItem` is generic over its `value` type,
|
|
56
|
+
bounded by `ValueLike` and defaulting to `Value`, instead of `Any`.
|
|
57
|
+
- `CommandInputHandler` and `ListInputHandler` are generic
|
|
58
|
+
over the value the selected input passes to the command,
|
|
59
|
+
bounded by `ValueLike`,
|
|
60
|
+
and `TextInputHandler` is a `CommandInputHandler[str]`.
|
|
61
|
+
`ListInputHandler`'s parameter defaults to `Value`,
|
|
62
|
+
while `CommandInputHandler`'s is contravariant and defaults to `Never`,
|
|
63
|
+
so bare annotations such as `Optional[CommandInputHandler]`
|
|
64
|
+
keep accepting every kind of handler.
|
|
65
|
+
The runtime classes cannot be subscripted on the Python 3.8 plugin host,
|
|
66
|
+
so parameterize a base class through an `if TYPE_CHECKING:` alias.
|
|
67
|
+
- `CommandInputHandler.preview()`, `validate()` and `confirm()` take that value type
|
|
68
|
+
rather than `str`,
|
|
69
|
+
because the host passes them the selected item's value, not its row text.
|
|
70
|
+
- `ListInputHandler.list_items()` may return any `Iterable`, not just a `list`,
|
|
71
|
+
and may mix the three item forms within it.
|
|
72
|
+
Note that a bare `tuple` of items type-checks
|
|
73
|
+
but is read at runtime as the `(items, index)` pre-select form.
|
|
74
|
+
- Every parameter through which a plugin passes a value into Sublime Text --
|
|
75
|
+
`Settings` mutators, `sublime.encode_value` and `expand_variables`,
|
|
76
|
+
`run_command` and its `format_command`, `html_format_command`
|
|
77
|
+
and `command_url` relatives, `set_project_data`, `begin_edit`
|
|
78
|
+
and `CompletionItem.command_completion` --
|
|
79
|
+
now accepts `ValueLike` or `CommandArgsLike`.
|
|
80
|
+
Return types, and the parameters Sublime Text fills in,
|
|
81
|
+
keep their narrower `Value` or `CommandArgs` types.
|
|
82
|
+
- `EventListener.on_query_context()` and `ViewEventListener.on_query_context()`
|
|
83
|
+
type their `operand` parameter as `Value` instead of `str`.
|
|
84
|
+
A `.sublime-keymap` context's `"operand"` may be a JSON string, number or boolean,
|
|
85
|
+
e.g. `"operand": 1` for `num_selections`,
|
|
86
|
+
and the plugin host hands it through unconverted.
|
|
87
|
+
- `set_timeout()` and `set_timeout_async()` type their `callback` as
|
|
88
|
+
`Callable[[], object]` instead of `Callable[[], Any]`,
|
|
89
|
+
since the runtime discards whatever the callback returns.
|
|
90
|
+
- `sublime.HTML` is annotated as `Literal[1]` rather than left to inference.
|
|
91
|
+
|
|
92
|
+
### Removed
|
|
93
|
+
|
|
94
|
+
- The `__repr__` and `__str__` declarations,
|
|
95
|
+
which only restated what `object` already says.
|
|
96
|
+
|
|
97
|
+
## 1.4200.0b1
|
|
98
|
+
|
|
99
|
+
Initial version
|
|
100
|
+
with stubs generated from upstream files of build 4200
|
|
101
|
+
and some overrides.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Technical decisions are recorded where they take effect --
|
|
4
|
+
in inline comments and in commit messages --
|
|
5
|
+
not in this file.
|
|
6
|
+
When you wonder *why* something is the way it is,
|
|
7
|
+
read the comment next to it;
|
|
8
|
+
this file only tells you where to look.
|
|
9
|
+
|
|
10
|
+
## Project structure
|
|
11
|
+
|
|
12
|
+
| Path | Contents |
|
|
13
|
+
| ------------------------ | -------- |
|
|
14
|
+
| `stubs/` | The generated `.pyi` files, one `-stubs` package per module. **Never edited by hand.** |
|
|
15
|
+
| `tools/generate_stubs.py`| The generator that derives `stubs/` from `references/`. |
|
|
16
|
+
| `tools/stub_overrides.py`| Declarative corrections the generator cannot derive on its own. |
|
|
17
|
+
| `references/python38/` | The annotated `sublime.py`, `sublime_plugin.py` and `sublime_types.py` shipped with the targeted Sublime Text build. |
|
|
18
|
+
| `tests/typing/` | Sample consumer code, type-checked to validate the stubs. |
|
|
19
|
+
| `.github/workflows/` | `ci.yml` for the stubs, `tools.yml` for the generator, `release.yml` for PyPI. |
|
|
20
|
+
|
|
21
|
+
The reference sources already carry the full signatures
|
|
22
|
+
and the reStructuredText docstrings the official docs are built from,
|
|
23
|
+
so the stubs are derived from them mechanically
|
|
24
|
+
rather than transcribed by hand.
|
|
25
|
+
|
|
26
|
+
### Branches
|
|
27
|
+
|
|
28
|
+
Each supported Sublime Text build line lives on its own branch,
|
|
29
|
+
because the build lines target different Python versions
|
|
30
|
+
and therefore need different stub syntax and type checker settings:
|
|
31
|
+
|
|
32
|
+
- `main` -- ST build 4200, Python 3.8, tagged `v1.4200.x`
|
|
33
|
+
- (planned) `main` moves on to ST build 4213, Python 3.14, tagged `v1.4213.x`,
|
|
34
|
+
and build 4200 continues on `st-4200`
|
|
35
|
+
|
|
36
|
+
Fixes that apply to more than one build line
|
|
37
|
+
are cherry-picked between branches,
|
|
38
|
+
so keep such commits small and self-contained.
|
|
39
|
+
|
|
40
|
+
## Generating the stubs
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
uv run python tools/generate_stubs.py # rewrite the .pyi files
|
|
44
|
+
uv run python tools/generate_stubs.py --check # what CI runs; fails on drift
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The generator refuses to guess.
|
|
48
|
+
Anything it cannot derive -- an unannotated parameter,
|
|
49
|
+
a bare `dict` that strict mode rejects --
|
|
50
|
+
is reported with the exact `stub_overrides` key to add,
|
|
51
|
+
and nothing is written until every one is resolved.
|
|
52
|
+
|
|
53
|
+
The check runs in the other direction too:
|
|
54
|
+
almost every override table is keyed by a name from the reference,
|
|
55
|
+
and an entry that matches nothing there is reported as stale.
|
|
56
|
+
Corrections therefore cannot quietly stop applying
|
|
57
|
+
when a member is renamed or removed in a later build.
|
|
58
|
+
The two exceptions are covered in "Adjusting the stubs" below.
|
|
59
|
+
|
|
60
|
+
## Adjusting the stubs
|
|
61
|
+
|
|
62
|
+
Corrections belong in `tools/stub_overrides.py`
|
|
63
|
+
if they concern a single member,
|
|
64
|
+
and in `tools/generate_stubs.py`
|
|
65
|
+
if they concern how the stubs are shaped as a whole.
|
|
66
|
+
The override tables are keyed by dotted names rooted at the module:
|
|
67
|
+
`sublime.Settings.to_dict` for a method,
|
|
68
|
+
`sublime.CompletionItem.__init__.kind` for a single parameter.
|
|
69
|
+
Each table's docstring says what it corrects;
|
|
70
|
+
add the entry, rerun the generator, commit the regenerated `.pyi` alongside it.
|
|
71
|
+
|
|
72
|
+
Record the reasoning for a non-obvious entry as a comment next to it,
|
|
73
|
+
with a `references/python38/<file>:<line>` pointer
|
|
74
|
+
to the reference code that justifies it.
|
|
75
|
+
If the correction changes what plugin authors have to write or can expect,
|
|
76
|
+
add the consequence -- not the reasoning -- to the notes in `README.md`.
|
|
77
|
+
|
|
78
|
+
The two exceptions to the staleness check are `EXTRA_TYPE_ALIASES`
|
|
79
|
+
and `EXTRA_TYPE_ALIAS_CLASSES`:
|
|
80
|
+
they add `sublime_types` names, such as `ValueLike`,
|
|
81
|
+
that have no reference-side counterpart at all,
|
|
82
|
+
so nothing validates them beyond the type checkers.
|
|
83
|
+
A name added to either table must also be added to `SUBLIME_TYPES_REEXPORTS`
|
|
84
|
+
for every module that re-exports it.
|
|
85
|
+
|
|
86
|
+
## Validating
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
uv sync --group dev
|
|
90
|
+
uv run pyright
|
|
91
|
+
uv run basedpyright
|
|
92
|
+
uv run mypy
|
|
93
|
+
uv run ty check --error-on-warning
|
|
94
|
+
uv run ruff check
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Because the real modules cannot be imported,
|
|
98
|
+
correctness is validated by strict-checking the sample consumer code
|
|
99
|
+
under `tests/typing/` with all four checkers.
|
|
100
|
+
There is no `stubtest` run,
|
|
101
|
+
which means divergence from the actual runtime API
|
|
102
|
+
is not caught automatically.
|
|
103
|
+
Extend `tests/typing/` when you touch an API that nothing there exercises.
|
|
104
|
+
|
|
105
|
+
ruff covers what the checkers cannot see:
|
|
106
|
+
its `flake8-pyi` rules judge whether a `.pyi` is *written* the way a stub should be,
|
|
107
|
+
which is a question about form rather than about meaning.
|
|
108
|
+
A finding under `stubs/` is therefore a bug in the generator.
|
|
109
|
+
Fix it in `tools/generate_stubs.py` and regenerate;
|
|
110
|
+
never edit a `.pyi` to silence ruff,
|
|
111
|
+
and never reach for `--fix` there.
|
|
112
|
+
|
|
113
|
+
Checker and lint settings, and why each is what it is,
|
|
114
|
+
are documented in `pyproject.toml`.
|
|
115
|
+
|
|
116
|
+
The checker versions are pinned in `uv.lock` and `tools/uv.lock`,
|
|
117
|
+
and CI installs exactly those.
|
|
118
|
+
Dependabot proposes upgrades once a month;
|
|
119
|
+
to upgrade by hand, run `uv lock --upgrade` in the root and in `tools/`,
|
|
120
|
+
then rerun all checks.
|
|
121
|
+
|
|
122
|
+
## The `tools/` sub-project
|
|
123
|
+
|
|
124
|
+
`tools/` is a separate, standalone uv project
|
|
125
|
+
with its own `pyproject.toml`, lockfile and virtualenv,
|
|
126
|
+
excluded from the four root checkers:
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
uv run --directory tools basedpyright # or: cd tools && uv run basedpyright
|
|
130
|
+
uv run --directory tools ruff check
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
basedpyright is the only type checker there,
|
|
134
|
+
with every rule at `error`;
|
|
135
|
+
ruff lints the same directory
|
|
136
|
+
under its own rule set and its own Python target,
|
|
137
|
+
which is why the root ruff run excludes `tools/`.
|
|
138
|
+
Both have their own [`Tools`](.github/workflows/tools.yml) workflow.
|
|
139
|
+
See `tools/pyproject.toml` for the settings and the reasons behind them.
|
|
140
|
+
|
|
141
|
+
## Onboarding a new Sublime Text build
|
|
142
|
+
|
|
143
|
+
1. Copy the build's `sublime.py`, `sublime_plugin.py` and `sublime_types.py`
|
|
144
|
+
into `references/python<version>/`.
|
|
145
|
+
2. Point `REFERENCE_DIR` and `ST_BUILD` in `tools/generate_stubs.py` at it.
|
|
146
|
+
3. Run the generator and resolve everything it reports as unresolved,
|
|
147
|
+
including any override it reports as stale.
|
|
148
|
+
4. Run the four type checkers and commit the regenerated `.pyi` files.
|
|
149
|
+
|
|
150
|
+
## Releasing
|
|
151
|
+
|
|
152
|
+
Tag `v1.${st_build_version}.${patch}` on the branch for that build line.
|
|
153
|
+
hatch-vcs derives the distribution version from the tag,
|
|
154
|
+
and the `Release` workflow publishes to PyPI via trusted publishing.
|
|
155
|
+
Add the changes to `CHANGELOG.md` before tagging.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sublime HQ Pty Ltd
|
|
4
|
+
Copyright (c) 2026 FichteFoll <fichtefoll2@googlemail.com>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sublime-text-stubs
|
|
3
|
+
Version: 1.4200.0
|
|
4
|
+
Summary: Typing stubs for the Sublime Text plugin API (sublime, sublime_plugin)
|
|
5
|
+
Project-URL: Homepage, https://github.com/SublimeText/sublime-text-stubs
|
|
6
|
+
Project-URL: Issues, https://github.com/SublimeText/sublime-text-stubs/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/SublimeText/sublime-text-stubs/blob/main/CHANGELOG.md
|
|
8
|
+
Author: FichteFoll
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: pep561,stubs,sublime-text,typing
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
16
|
+
Classifier: Topic :: Text Editors
|
|
17
|
+
Classifier: Typing :: Stubs Only
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# sublime-text-stubs
|
|
22
|
+
|
|
23
|
+
[PEP 561](https://peps.python.org/pep-0561/) typing stubs
|
|
24
|
+
for the Sublime Text plugin API,
|
|
25
|
+
covering the `sublime`, `sublime_plugin` and `sublime_types` modules.
|
|
26
|
+
|
|
27
|
+
The stubs carry the API documentation as docstrings,
|
|
28
|
+
so hovering a symbol in an editor shows the same prose
|
|
29
|
+
as the [official API reference](https://www.sublimetext.com/docs/api_reference.html).
|
|
30
|
+
|
|
31
|
+
Sublime Text exposes these modules only inside its own embedded interpreter,
|
|
32
|
+
so they cannot be imported or introspected from a normal Python environment.
|
|
33
|
+
Installing this package as a dev dependency
|
|
34
|
+
gives type checkers and editors something to resolve them against.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
uv add --dev sublime-text-stubs
|
|
40
|
+
# or
|
|
41
|
+
pip install --upgrade sublime-text-stubs
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Versioning
|
|
45
|
+
|
|
46
|
+
Versions follow the scheme `1.${st_build_version}.${patch}`:
|
|
47
|
+
|
|
48
|
+
| Version | Sublime Text build | Embedded Python |
|
|
49
|
+
| ----------- | ------------------ | --------------- |
|
|
50
|
+
| `1.4200.*` | 4200 (stable) | 3.8 |
|
|
51
|
+
|
|
52
|
+
The leading `1` is the schema version of this package itself,
|
|
53
|
+
the middle segment is the Sublime Text build the stubs describe,
|
|
54
|
+
and the trailing segment is the patch level within that build.
|
|
55
|
+
This is deliberately not semantic versioning.
|
|
56
|
+
|
|
57
|
+
Pin the build you target:
|
|
58
|
+
|
|
59
|
+
```toml
|
|
60
|
+
sublime-text-stubs = "==1.4200.*"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Sublime Text 4 also still ships a legacy Python 3.3 runtime.
|
|
64
|
+
It is scheduled for removal and is not targeted by this package.
|
|
65
|
+
|
|
66
|
+
## Notes for plugin authors
|
|
67
|
+
|
|
68
|
+
- **Commands do not declare `run`.**
|
|
69
|
+
Sublime Text invokes it with command-specific keyword arguments,
|
|
70
|
+
so the stubs leave the signature to your subclass.
|
|
71
|
+
Write `def run(self, **kwargs)`,
|
|
72
|
+
or `def run(self, edit, **kwargs)` for a `TextCommand`.
|
|
73
|
+
- **`is_enabled`, `is_visible`, `is_checked` and `description`**
|
|
74
|
+
receive their command arguments the same dynamic way,
|
|
75
|
+
but are declared without parameters.
|
|
76
|
+
`def is_enabled(self)`, `def is_enabled(self, my_arg="")`
|
|
77
|
+
and `def is_enabled(self, **kwargs)` all type-check.
|
|
78
|
+
A *required* parameter is rejected,
|
|
79
|
+
and correctly so:
|
|
80
|
+
such an override also raises `TypeError` at runtime
|
|
81
|
+
when the command is invoked without that argument.
|
|
82
|
+
- **`TextChangeListener.buffer` is `sublime.Buffer`, never `None`.**
|
|
83
|
+
- **`ValueLike` is what you pass in, `Value` is what you get back.**
|
|
84
|
+
Every parameter a plugin hands a value to is annotated `ValueLike`,
|
|
85
|
+
which accepts arbitrary sequences and mappings,
|
|
86
|
+
so a `List[str]` variable can be passed directly
|
|
87
|
+
even though the invariant `list[Value]` would reject it:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
tags: List[str] = ["fix", "feature"]
|
|
91
|
+
settings.set("tags", tags)
|
|
92
|
+
sublime.encode_value(tags)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Two things it does not model.
|
|
96
|
+
A `collections.abc.Mapping` that is not a `dict` type-checks as `ValueLike`,
|
|
97
|
+
but is rejected at runtime everywhere except `Settings.update`,
|
|
98
|
+
which genuinely accepts any mapping.
|
|
99
|
+
And a value that makes the round trip through Sublime Text
|
|
100
|
+
comes back as a plain `list` or `dict`,
|
|
101
|
+
not as the type that was passed;
|
|
102
|
+
`bytes` in particular is accepted and arrives back as `list[int]`.
|
|
103
|
+
|
|
104
|
+
`sublime.Region` is rejected by both the checkers and the runtime.
|
|
105
|
+
- **The input handlers are generic.**
|
|
106
|
+
`ListInputHandler` and `sublime.ListInputItem` take a type parameter
|
|
107
|
+
for the value the selected row passes to the command,
|
|
108
|
+
and that value type is what `list_items()`, `description()`,
|
|
109
|
+
`preview()`, `validate()` and `confirm()` traffic in.
|
|
110
|
+
You may parameterize on anything a `ValueLike` allows,
|
|
111
|
+
so `ListInputHandler[List[str]]` type-checks,
|
|
112
|
+
while a bare annotation resolves to `Value`,
|
|
113
|
+
which is what the runtime actually delivers.
|
|
114
|
+
`TextInputHandler` is a `CommandInputHandler[str]`.
|
|
115
|
+
A bare `CommandInputHandler`,
|
|
116
|
+
as in the return types of `Command.input()` and `next_input()`,
|
|
117
|
+
still accepts every kind of handler,
|
|
118
|
+
so `Optional[sublime_plugin.CommandInputHandler]` keeps working unchanged.
|
|
119
|
+
The real classes cannot be subscripted on the Python 3.8 plugin host,
|
|
120
|
+
so parameterize a base class through an `if TYPE_CHECKING:` alias
|
|
121
|
+
and quote subscripted annotations:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
if TYPE_CHECKING:
|
|
125
|
+
_StrListInputHandler = sublime_plugin.ListInputHandler[str]
|
|
126
|
+
else:
|
|
127
|
+
_StrListInputHandler = sublime_plugin.ListInputHandler
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class NameInputHandler(_StrListInputHandler):
|
|
131
|
+
...
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **Several `sublime_types` names exist only in these stubs**,
|
|
135
|
+
not in the real module at runtime,
|
|
136
|
+
so each must be imported inside an `if TYPE_CHECKING:` block:
|
|
137
|
+
- `ModifierKeys`, the type of the `modifier_keys` entry of an `Event`.
|
|
138
|
+
- `UIInfo` and its parts `UIInfoSystem`, `UIInfoTheme`,
|
|
139
|
+
`UIInfoColorScheme` and `UIInfoPalette`,
|
|
140
|
+
describing the return value of `sublime.ui_info()`.
|
|
141
|
+
- `ScopeStyle`, the return value of `View.style_for_scope()`.
|
|
142
|
+
- `MacroStep`, the entries of the list `sublime.get_macro()` returns.
|
|
143
|
+
- `WindowLayout`, used by `Window.layout()`, `Window.get_layout()`
|
|
144
|
+
and `Window.set_layout()`.
|
|
145
|
+
- `WindowVariables`, the return value of `Window.extract_variables()`.
|
|
146
|
+
- `FontOptions`, the default and callback argument types
|
|
147
|
+
of `choose_font_dialog()`.
|
|
148
|
+
- `ValueLike`, the covariant companion to `Value`,
|
|
149
|
+
accepted wherever a plugin passes a value into Sublime Text.
|
|
150
|
+
- `CommandArgsLike`, the same widening applied to command `args`,
|
|
151
|
+
mirroring `CommandArgs`.
|
|
152
|
+
|
|
153
|
+
The stubs are not validated against the running editor,
|
|
154
|
+
so divergences from the actual runtime API are possible.
|
|
155
|
+
Please [report](https://github.com/SublimeText/sublime-text-stubs/issues) any you find.
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
160
|
+
for the project structure,
|
|
161
|
+
how the stubs are generated and validated,
|
|
162
|
+
and how to correct them.
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT. See [LICENSE](LICENSE).
|
|
167
|
+
The stubs are derived from the API sources shipped with Sublime Text,
|
|
168
|
+
(c) Sublime HQ Pty Ltd,
|
|
169
|
+
and used with permission under the same license.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# sublime-text-stubs
|
|
2
|
+
|
|
3
|
+
[PEP 561](https://peps.python.org/pep-0561/) typing stubs
|
|
4
|
+
for the Sublime Text plugin API,
|
|
5
|
+
covering the `sublime`, `sublime_plugin` and `sublime_types` modules.
|
|
6
|
+
|
|
7
|
+
The stubs carry the API documentation as docstrings,
|
|
8
|
+
so hovering a symbol in an editor shows the same prose
|
|
9
|
+
as the [official API reference](https://www.sublimetext.com/docs/api_reference.html).
|
|
10
|
+
|
|
11
|
+
Sublime Text exposes these modules only inside its own embedded interpreter,
|
|
12
|
+
so they cannot be imported or introspected from a normal Python environment.
|
|
13
|
+
Installing this package as a dev dependency
|
|
14
|
+
gives type checkers and editors something to resolve them against.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
uv add --dev sublime-text-stubs
|
|
20
|
+
# or
|
|
21
|
+
pip install --upgrade sublime-text-stubs
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Versioning
|
|
25
|
+
|
|
26
|
+
Versions follow the scheme `1.${st_build_version}.${patch}`:
|
|
27
|
+
|
|
28
|
+
| Version | Sublime Text build | Embedded Python |
|
|
29
|
+
| ----------- | ------------------ | --------------- |
|
|
30
|
+
| `1.4200.*` | 4200 (stable) | 3.8 |
|
|
31
|
+
|
|
32
|
+
The leading `1` is the schema version of this package itself,
|
|
33
|
+
the middle segment is the Sublime Text build the stubs describe,
|
|
34
|
+
and the trailing segment is the patch level within that build.
|
|
35
|
+
This is deliberately not semantic versioning.
|
|
36
|
+
|
|
37
|
+
Pin the build you target:
|
|
38
|
+
|
|
39
|
+
```toml
|
|
40
|
+
sublime-text-stubs = "==1.4200.*"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Sublime Text 4 also still ships a legacy Python 3.3 runtime.
|
|
44
|
+
It is scheduled for removal and is not targeted by this package.
|
|
45
|
+
|
|
46
|
+
## Notes for plugin authors
|
|
47
|
+
|
|
48
|
+
- **Commands do not declare `run`.**
|
|
49
|
+
Sublime Text invokes it with command-specific keyword arguments,
|
|
50
|
+
so the stubs leave the signature to your subclass.
|
|
51
|
+
Write `def run(self, **kwargs)`,
|
|
52
|
+
or `def run(self, edit, **kwargs)` for a `TextCommand`.
|
|
53
|
+
- **`is_enabled`, `is_visible`, `is_checked` and `description`**
|
|
54
|
+
receive their command arguments the same dynamic way,
|
|
55
|
+
but are declared without parameters.
|
|
56
|
+
`def is_enabled(self)`, `def is_enabled(self, my_arg="")`
|
|
57
|
+
and `def is_enabled(self, **kwargs)` all type-check.
|
|
58
|
+
A *required* parameter is rejected,
|
|
59
|
+
and correctly so:
|
|
60
|
+
such an override also raises `TypeError` at runtime
|
|
61
|
+
when the command is invoked without that argument.
|
|
62
|
+
- **`TextChangeListener.buffer` is `sublime.Buffer`, never `None`.**
|
|
63
|
+
- **`ValueLike` is what you pass in, `Value` is what you get back.**
|
|
64
|
+
Every parameter a plugin hands a value to is annotated `ValueLike`,
|
|
65
|
+
which accepts arbitrary sequences and mappings,
|
|
66
|
+
so a `List[str]` variable can be passed directly
|
|
67
|
+
even though the invariant `list[Value]` would reject it:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
tags: List[str] = ["fix", "feature"]
|
|
71
|
+
settings.set("tags", tags)
|
|
72
|
+
sublime.encode_value(tags)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Two things it does not model.
|
|
76
|
+
A `collections.abc.Mapping` that is not a `dict` type-checks as `ValueLike`,
|
|
77
|
+
but is rejected at runtime everywhere except `Settings.update`,
|
|
78
|
+
which genuinely accepts any mapping.
|
|
79
|
+
And a value that makes the round trip through Sublime Text
|
|
80
|
+
comes back as a plain `list` or `dict`,
|
|
81
|
+
not as the type that was passed;
|
|
82
|
+
`bytes` in particular is accepted and arrives back as `list[int]`.
|
|
83
|
+
|
|
84
|
+
`sublime.Region` is rejected by both the checkers and the runtime.
|
|
85
|
+
- **The input handlers are generic.**
|
|
86
|
+
`ListInputHandler` and `sublime.ListInputItem` take a type parameter
|
|
87
|
+
for the value the selected row passes to the command,
|
|
88
|
+
and that value type is what `list_items()`, `description()`,
|
|
89
|
+
`preview()`, `validate()` and `confirm()` traffic in.
|
|
90
|
+
You may parameterize on anything a `ValueLike` allows,
|
|
91
|
+
so `ListInputHandler[List[str]]` type-checks,
|
|
92
|
+
while a bare annotation resolves to `Value`,
|
|
93
|
+
which is what the runtime actually delivers.
|
|
94
|
+
`TextInputHandler` is a `CommandInputHandler[str]`.
|
|
95
|
+
A bare `CommandInputHandler`,
|
|
96
|
+
as in the return types of `Command.input()` and `next_input()`,
|
|
97
|
+
still accepts every kind of handler,
|
|
98
|
+
so `Optional[sublime_plugin.CommandInputHandler]` keeps working unchanged.
|
|
99
|
+
The real classes cannot be subscripted on the Python 3.8 plugin host,
|
|
100
|
+
so parameterize a base class through an `if TYPE_CHECKING:` alias
|
|
101
|
+
and quote subscripted annotations:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
if TYPE_CHECKING:
|
|
105
|
+
_StrListInputHandler = sublime_plugin.ListInputHandler[str]
|
|
106
|
+
else:
|
|
107
|
+
_StrListInputHandler = sublime_plugin.ListInputHandler
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class NameInputHandler(_StrListInputHandler):
|
|
111
|
+
...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- **Several `sublime_types` names exist only in these stubs**,
|
|
115
|
+
not in the real module at runtime,
|
|
116
|
+
so each must be imported inside an `if TYPE_CHECKING:` block:
|
|
117
|
+
- `ModifierKeys`, the type of the `modifier_keys` entry of an `Event`.
|
|
118
|
+
- `UIInfo` and its parts `UIInfoSystem`, `UIInfoTheme`,
|
|
119
|
+
`UIInfoColorScheme` and `UIInfoPalette`,
|
|
120
|
+
describing the return value of `sublime.ui_info()`.
|
|
121
|
+
- `ScopeStyle`, the return value of `View.style_for_scope()`.
|
|
122
|
+
- `MacroStep`, the entries of the list `sublime.get_macro()` returns.
|
|
123
|
+
- `WindowLayout`, used by `Window.layout()`, `Window.get_layout()`
|
|
124
|
+
and `Window.set_layout()`.
|
|
125
|
+
- `WindowVariables`, the return value of `Window.extract_variables()`.
|
|
126
|
+
- `FontOptions`, the default and callback argument types
|
|
127
|
+
of `choose_font_dialog()`.
|
|
128
|
+
- `ValueLike`, the covariant companion to `Value`,
|
|
129
|
+
accepted wherever a plugin passes a value into Sublime Text.
|
|
130
|
+
- `CommandArgsLike`, the same widening applied to command `args`,
|
|
131
|
+
mirroring `CommandArgs`.
|
|
132
|
+
|
|
133
|
+
The stubs are not validated against the running editor,
|
|
134
|
+
so divergences from the actual runtime API are possible.
|
|
135
|
+
Please [report](https://github.com/SublimeText/sublime-text-stubs/issues) any you find.
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
140
|
+
for the project structure,
|
|
141
|
+
how the stubs are generated and validated,
|
|
142
|
+
and how to correct them.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT. See [LICENSE](LICENSE).
|
|
147
|
+
The stubs are derived from the API sources shipped with Sublime Text,
|
|
148
|
+
(c) Sublime HQ Pty Ltd,
|
|
149
|
+
and used with permission under the same license.
|