py-vision-free 1.0.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.
Files changed (72) hide show
  1. py_vision_free-1.0.0/CHANGELOG.md +19 -0
  2. py_vision_free-1.0.0/LICENSE +21 -0
  3. py_vision_free-1.0.0/MANIFEST.in +11 -0
  4. py_vision_free-1.0.0/NOTICE.md +36 -0
  5. py_vision_free-1.0.0/PKG-INFO +79 -0
  6. py_vision_free-1.0.0/README.md +47 -0
  7. py_vision_free-1.0.0/pyproject.toml +81 -0
  8. py_vision_free-1.0.0/setup.cfg +4 -0
  9. py_vision_free-1.0.0/src/py_vision_free/__init__.py +61 -0
  10. py_vision_free-1.0.0/src/py_vision_free/_compat.py +49 -0
  11. py_vision_free-1.0.0/src/py_vision_free/app.py +1299 -0
  12. py_vision_free-1.0.0/src/py_vision_free/color.py +190 -0
  13. py_vision_free-1.0.0/src/py_vision_free/commands.py +23 -0
  14. py_vision_free-1.0.0/src/py_vision_free/editors/__init__.py +18 -0
  15. py_vision_free-1.0.0/src/py_vision_free/editors/dialogs.py +222 -0
  16. py_vision_free-1.0.0/src/py_vision_free/editors/editor.py +922 -0
  17. py_vision_free-1.0.0/src/py_vision_free/editors/indicator.py +44 -0
  18. py_vision_free-1.0.0/src/py_vision_free/editors/search.py +290 -0
  19. py_vision_free-1.0.0/src/py_vision_free/events.py +277 -0
  20. py_vision_free-1.0.0/src/py_vision_free/frame.py +116 -0
  21. py_vision_free-1.0.0/src/py_vision_free/fspolicy.py +120 -0
  22. py_vision_free-1.0.0/src/py_vision_free/geometry.py +106 -0
  23. py_vision_free-1.0.0/src/py_vision_free/help/__init__.py +74 -0
  24. py_vision_free-1.0.0/src/py_vision_free/help/__main__.py +54 -0
  25. py_vision_free-1.0.0/src/py_vision_free/help/context.py +138 -0
  26. py_vision_free-1.0.0/src/py_vision_free/help/format.py +561 -0
  27. py_vision_free-1.0.0/src/py_vision_free/help/model.py +373 -0
  28. py_vision_free-1.0.0/src/py_vision_free/help/viewer.py +237 -0
  29. py_vision_free-1.0.0/src/py_vision_free/icons.py +275 -0
  30. py_vision_free-1.0.0/src/py_vision_free/platform/__init__.py +59 -0
  31. py_vision_free-1.0.0/src/py_vision_free/platform/headless.py +130 -0
  32. py_vision_free-1.0.0/src/py_vision_free/platform/posix.py +249 -0
  33. py_vision_free-1.0.0/src/py_vision_free/platform/termprofile.py +96 -0
  34. py_vision_free-1.0.0/src/py_vision_free/platform/vtinput.py +362 -0
  35. py_vision_free-1.0.0/src/py_vision_free/platform/win32.py +351 -0
  36. py_vision_free-1.0.0/src/py_vision_free/py.typed +0 -0
  37. py_vision_free-1.0.0/src/py_vision_free/screen.py +328 -0
  38. py_vision_free-1.0.0/src/py_vision_free/screens.py +152 -0
  39. py_vision_free-1.0.0/src/py_vision_free/testing.py +54 -0
  40. py_vision_free-1.0.0/src/py_vision_free/text.py +203 -0
  41. py_vision_free-1.0.0/src/py_vision_free/theme.py +376 -0
  42. py_vision_free-1.0.0/src/py_vision_free/validate.py +337 -0
  43. py_vision_free-1.0.0/src/py_vision_free/views.py +505 -0
  44. py_vision_free-1.0.0/src/py_vision_free/widgets/__init__.py +118 -0
  45. py_vision_free-1.0.0/src/py_vision_free/widgets/busy.py +148 -0
  46. py_vision_free-1.0.0/src/py_vision_free/widgets/button.py +91 -0
  47. py_vision_free-1.0.0/src/py_vision_free/widgets/cluster.py +252 -0
  48. py_vision_free-1.0.0/src/py_vision_free/widgets/combobox.py +127 -0
  49. py_vision_free-1.0.0/src/py_vision_free/widgets/diffview.py +612 -0
  50. py_vision_free-1.0.0/src/py_vision_free/widgets/history.py +277 -0
  51. py_vision_free-1.0.0/src/py_vision_free/widgets/inputline.py +269 -0
  52. py_vision_free-1.0.0/src/py_vision_free/widgets/listbox.py +176 -0
  53. py_vision_free-1.0.0/src/py_vision_free/widgets/listviewer.py +180 -0
  54. py_vision_free-1.0.0/src/py_vision_free/widgets/markdown.py +540 -0
  55. py_vision_free-1.0.0/src/py_vision_free/widgets/memo.py +48 -0
  56. py_vision_free-1.0.0/src/py_vision_free/widgets/menu.py +836 -0
  57. py_vision_free-1.0.0/src/py_vision_free/widgets/msgbox.py +171 -0
  58. py_vision_free-1.0.0/src/py_vision_free/widgets/prompt.py +117 -0
  59. py_vision_free-1.0.0/src/py_vision_free/widgets/richview.py +797 -0
  60. py_vision_free-1.0.0/src/py_vision_free/widgets/scrollbar.py +144 -0
  61. py_vision_free-1.0.0/src/py_vision_free/widgets/scroller.py +120 -0
  62. py_vision_free-1.0.0/src/py_vision_free/widgets/spinner.py +134 -0
  63. py_vision_free-1.0.0/src/py_vision_free/widgets/static.py +75 -0
  64. py_vision_free-1.0.0/src/py_vision_free/widgets/tabs.py +386 -0
  65. py_vision_free-1.0.0/src/py_vision_free/widgets/terminal.py +178 -0
  66. py_vision_free-1.0.0/src/py_vision_free/widgets/transcript.py +764 -0
  67. py_vision_free-1.0.0/src/py_vision_free/window.py +399 -0
  68. py_vision_free-1.0.0/src/py_vision_free.egg-info/PKG-INFO +79 -0
  69. py_vision_free-1.0.0/src/py_vision_free.egg-info/SOURCES.txt +70 -0
  70. py_vision_free-1.0.0/src/py_vision_free.egg-info/dependency_links.txt +1 -0
  71. py_vision_free-1.0.0/src/py_vision_free.egg-info/requires.txt +4 -0
  72. py_vision_free-1.0.0/src/py_vision_free.egg-info/top_level.txt +1 -0
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2026-11-29)
4
+
5
+ First public release. A text-mode UI toolkit in the style of Turbo Vision, written
6
+ with the Python standard library only (Python 3.12 or newer).
7
+
8
+ - Program, desktop, windows, dialogs, menu bar and status line (with named segments).
9
+ - Widgets: buttons, input lines, check boxes and radio buttons, list boxes, combo box,
10
+ spinner, memo, tab dialog, scroll bars, message and input boxes, a permission box.
11
+ - Text views: `RichView`, `TranscriptView` with streaming Markdown (`MarkdownStream`),
12
+ `PromptMemo`, `DiffView`, `Terminal`, a busy indicator.
13
+ - An editor view with search and replace, a help system (F1) and a shell escape
14
+ (`Program.run_shell`, the Turbo Vision "DOS Shell").
15
+ - Worker threads: `Program.post`, `post_once` and `ask_from_thread`.
16
+ - Windows console, POSIX terminals (including the Linux text console) and a headless
17
+ terminal.
18
+ - Colour depth override: `PY_VISION_COLORS` (`24bit`, `256`, `16`, `mono`).
19
+ - Examples in the shape of the Turbo Vision demos: `hello`, `mmenu`, `palette`, `tvdemo`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Peter Kokosharov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ # Source distribution = the package plus the files a reader or packager needs.
2
+ # Tests, docs, examples, tools and the C++ comparison build live in the Git repository only.
3
+ include LICENSE NOTICE.md README.md CHANGELOG.md pyproject.toml
4
+ prune tests
5
+ prune docs
6
+ prune examples
7
+ prune tools
8
+ prune cpp
9
+ prune build
10
+ prune .github
11
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,36 @@
1
+ # Notice
2
+
3
+ py-vision-free
4
+ Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>
5
+ Licensed under the MIT License (see LICENSE).
6
+
7
+ py-vision-free is an independent Python implementation of a text-mode UI toolkit
8
+ in the style of Turbo Vision. Its Python code was written from the documented and
9
+ observed behaviour of Turbo Vision; it is not a translation of the C++ source code.
10
+ It is not affiliated with or endorsed by Borland, Embarcadero or magiblot.
11
+
12
+ ## Thanks
13
+
14
+ - Borland International, whose Turbo Vision (1990-1994) defined this way of building
15
+ text-mode programs, and who made its source code public.
16
+ - magiblot and the contributors of magiblot/tvision
17
+ (https://github.com/magiblot/tvision), the modern cross-platform Turbo Vision that
18
+ served as the behaviour reference for this package.
19
+
20
+ ## The C++ code in cpp/tvision
21
+
22
+ cpp/tvision is a git submodule that points to magiblot/tvision, pinned to commit
23
+ af3a4295a88502aef39fc7e2b238c7d078d34688 (2026-11-14; see cpp/README.md). It is not part of
24
+ the Python package and is not included in the files published on PyPI. Its terms are
25
+ in cpp/tvision/COPYRIGHT and are summarised here:
26
+
27
+ - The original Turbo Vision source code was made public by Borland International
28
+ with a disclaimer of warranty and liability only; no licence grant accompanies it.
29
+ - Modifications by magiblot and other contributors, and code written from scratch:
30
+ MIT License, Copyright 2019-2025 magiblot <magiblot@hotmail.com>.
31
+ - Included third-party components: fast utoa() (Copyright (C) 2014 Milo Yip, MIT);
32
+ wcwidth() (Markus Kuhn, 2007); Flexible and Economical UTF-8 Decoder
33
+ (Copyright (c) 2008-2010 Bjoern Hoehrmann, MIT).
34
+
35
+ The build scripts and patches in cpp/build and cpp/patches are part of this project
36
+ and are MIT licensed like the rest of it.
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: py-vision-free
3
+ Version: 1.0.0
4
+ Summary: A text-mode UI toolkit in the style of Turbo Vision, standard library only
5
+ Author-email: Peter Kokosharov <peter.kokosharov@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/peterkokosharov/py-vision-free
8
+ Project-URL: Source, https://github.com/peterkokosharov/py-vision-free
9
+ Project-URL: Changelog, https://github.com/peterkokosharov/py-vision-free/blob/main/CHANGELOG.md
10
+ Keywords: tui,terminal,console,text-ui,widgets,turbo-vision
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: User Interfaces
22
+ Classifier: Topic :: Terminals
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.12
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ License-File: NOTICE.md
28
+ Provides-Extra: dev
29
+ Requires-Dist: ruff==0.17.6; extra == "dev"
30
+ Requires-Dist: mypy==2.4.1; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # py-vision-free
34
+
35
+ A text-mode UI toolkit for Python: windows, dialogs, menus, a status line and input
36
+ widgets in the terminal. Standard library only, Python 3.12 or newer, on Windows,
37
+ Linux and macOS.
38
+
39
+ Inspired by Borland Turbo Vision; used by rex for its terminal UI.
40
+
41
+ ## Install
42
+
43
+ pip install py-vision-free
44
+
45
+ The import name is `py_vision_free`.
46
+
47
+ ## A first program
48
+
49
+ ```python
50
+ from py_vision_free import Application, Command, Rect
51
+ from py_vision_free.platform import open_terminal
52
+ from py_vision_free.widgets import StaticText, StatusItem, StatusLine
53
+ from py_vision_free.window import Window
54
+
55
+
56
+ class Hello(Application):
57
+ def setup(self) -> None:
58
+ w, h = self.screen.width, self.screen.height
59
+ self.set_status_line(StatusLine(Rect(0, h - 1, w, h), [
60
+ StatusItem("~Alt-X~ Exit", "Alt+X", Command.QUIT),
61
+ ]))
62
+ win = Window(Rect(10, 3, 50, 10), "Hello")
63
+ win.insert(StaticText(Rect(2, 1, 36, 4), "Hello, terminal!", role="window"))
64
+ self.desktop.insert(win)
65
+
66
+
67
+ Hello(open_terminal()).run()
68
+ ```
69
+
70
+ Alt-X quits. The `examples/` folder has `hello.py`, `mmenu.py`, `palette.py` and
71
+ `tvdemo/`, small programs in the shape of the demos that come with Turbo Vision.
72
+
73
+ ## Links
74
+
75
+ - [User guide](https://github.com/peterkokosharov/py-vision-free/blob/main/docs/USER-GUIDE.md)
76
+ and [API reference](https://github.com/peterkokosharov/py-vision-free/blob/main/docs/api/README.md)
77
+ - [NOTICE](https://github.com/peterkokosharov/py-vision-free/blob/main/NOTICE.md)
78
+ - [License](https://github.com/peterkokosharov/py-vision-free/blob/main/LICENSE) (MIT)
79
+ - Upstream C++ Turbo Vision: [magiblot/tvision](https://github.com/magiblot/tvision)
@@ -0,0 +1,47 @@
1
+ # py-vision-free
2
+
3
+ A text-mode UI toolkit for Python: windows, dialogs, menus, a status line and input
4
+ widgets in the terminal. Standard library only, Python 3.12 or newer, on Windows,
5
+ Linux and macOS.
6
+
7
+ Inspired by Borland Turbo Vision; used by rex for its terminal UI.
8
+
9
+ ## Install
10
+
11
+ pip install py-vision-free
12
+
13
+ The import name is `py_vision_free`.
14
+
15
+ ## A first program
16
+
17
+ ```python
18
+ from py_vision_free import Application, Command, Rect
19
+ from py_vision_free.platform import open_terminal
20
+ from py_vision_free.widgets import StaticText, StatusItem, StatusLine
21
+ from py_vision_free.window import Window
22
+
23
+
24
+ class Hello(Application):
25
+ def setup(self) -> None:
26
+ w, h = self.screen.width, self.screen.height
27
+ self.set_status_line(StatusLine(Rect(0, h - 1, w, h), [
28
+ StatusItem("~Alt-X~ Exit", "Alt+X", Command.QUIT),
29
+ ]))
30
+ win = Window(Rect(10, 3, 50, 10), "Hello")
31
+ win.insert(StaticText(Rect(2, 1, 36, 4), "Hello, terminal!", role="window"))
32
+ self.desktop.insert(win)
33
+
34
+
35
+ Hello(open_terminal()).run()
36
+ ```
37
+
38
+ Alt-X quits. The `examples/` folder has `hello.py`, `mmenu.py`, `palette.py` and
39
+ `tvdemo/`, small programs in the shape of the demos that come with Turbo Vision.
40
+
41
+ ## Links
42
+
43
+ - [User guide](https://github.com/peterkokosharov/py-vision-free/blob/main/docs/USER-GUIDE.md)
44
+ and [API reference](https://github.com/peterkokosharov/py-vision-free/blob/main/docs/api/README.md)
45
+ - [NOTICE](https://github.com/peterkokosharov/py-vision-free/blob/main/NOTICE.md)
46
+ - [License](https://github.com/peterkokosharov/py-vision-free/blob/main/LICENSE) (MIT)
47
+ - Upstream C++ Turbo Vision: [magiblot/tvision](https://github.com/magiblot/tvision)
@@ -0,0 +1,81 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "py-vision-free"
7
+ version = "1.0.0"
8
+ description = "A text-mode UI toolkit in the style of Turbo Vision, standard library only"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE", "NOTICE.md"]
12
+ authors = [{ name = "Peter Kokosharov", email = "peter.kokosharov@gmail.com" }]
13
+ requires-python = ">=3.12"
14
+ # Runtime: Python standard library only. No third-party runtime dependencies.
15
+ dependencies = []
16
+ keywords = ["tui", "terminal", "console", "text-ui", "widgets", "turbo-vision"]
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Developers",
21
+ "Operating System :: Microsoft :: Windows",
22
+ "Operating System :: POSIX :: Linux",
23
+ "Operating System :: MacOS",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Software Development :: User Interfaces",
29
+ "Topic :: Terminals",
30
+ "Typing :: Typed",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/peterkokosharov/py-vision-free"
35
+ Source = "https://github.com/peterkokosharov/py-vision-free"
36
+ Changelog = "https://github.com/peterkokosharov/py-vision-free/blob/main/CHANGELOG.md"
37
+
38
+ [project.optional-dependencies]
39
+ # Development tooling only (lint, type check); never required at runtime.
40
+ dev = [
41
+ "ruff==0.17.6",
42
+ "mypy==2.4.1",
43
+ ]
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
47
+ include = ["py_vision_free*"]
48
+
49
+ [tool.setuptools.package-data]
50
+ py_vision_free = ["py.typed"]
51
+
52
+ [tool.ruff]
53
+ line-length = 100
54
+ target-version = "py312"
55
+ src = ["src"]
56
+
57
+ [tool.ruff.lint]
58
+ select = ["E", "F", "I", "W", "UP", "B", "C4", "SIM"]
59
+ ignore = [
60
+ "E501", # line length is a reading aid, not a gate
61
+ "SIM102", # a nested "if" often keeps a side-effecting call visible; merging hides it
62
+ "SIM114", # separate "elif" branches with the same body keep each condition readable
63
+ "SIM108", # long conditional expressions read worse than a plain if/else block
64
+ ]
65
+
66
+ [tool.ruff.lint.isort]
67
+ # examples and tools import the package like an installed one; sort it as first party.
68
+ known-first-party = ["py_vision_free"]
69
+
70
+ [tool.ruff.lint.flake8-bugbear]
71
+ # Rect is a frozen dataclass, so it is safe as a default argument value.
72
+ extend-immutable-calls = ["py_vision_free.geometry.Rect"]
73
+
74
+ [tool.mypy]
75
+ python_version = "3.12"
76
+ files = ["src"]
77
+ warn_unused_configs = true
78
+ warn_unused_ignores = true
79
+ warn_redundant_casts = true
80
+ no_implicit_optional = true
81
+ check_untyped_defs = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>
2
+ # SPDX-License-Identifier: MIT
3
+ # AI models: claude-opus-4-8, claude-sonnet-5-5, claude-opus-5-5
4
+ """py_vision_free - a small, standard-library text-UI toolkit.
5
+
6
+ Independent design inspired by Turbo Vision (see ``docs/DESIGN.md``); it is
7
+ not a translation of Borland-origin tvision code. The package provides the
8
+ screen buffer with diffing, the view/group model, windows and dialogs, the
9
+ event loop, cross-platform rendering and input, and the widgets.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from .app import Application, Desktop, Program
15
+ from .commands import CMD_SCREEN_BASE, COMMAND_SET_CHANGED
16
+ from .events import (
17
+ CMD_USER,
18
+ Command,
19
+ Event,
20
+ EventKind,
21
+ Mod,
22
+ broadcast_event,
23
+ command_event,
24
+ key_event,
25
+ key_spec,
26
+ mouse_event,
27
+ paste_event,
28
+ resize_event,
29
+ )
30
+ from .geometry import Point, Rect
31
+ from .screen import Buffer, DrawContext, Screen
32
+ from .screens import ScreenSwitcher
33
+ from .theme import Style, Theme, get_theme
34
+ from .validate import (
35
+ FilterValidator,
36
+ LookupValidator,
37
+ PXPictureValidator,
38
+ RangeValidator,
39
+ StringLookupValidator,
40
+ Validator,
41
+ )
42
+ from .views import Group, Grow, Option, State, View
43
+ from .window import Dialog, Window
44
+
45
+ __version__ = "1.0.0" # equal to pyproject.toml and the release tag (publish.yml checks)
46
+
47
+ __all__ = [
48
+ "__version__",
49
+ "Point", "Rect",
50
+ "Style", "Theme", "get_theme",
51
+ "Buffer", "DrawContext", "Screen",
52
+ "Event", "EventKind", "Mod", "Command", "CMD_USER",
53
+ "key_event", "command_event", "broadcast_event", "mouse_event",
54
+ "paste_event", "resize_event", "key_spec",
55
+ "View", "Group", "State", "Option", "Grow",
56
+ "Window", "Dialog",
57
+ "Program", "Application", "Desktop",
58
+ "COMMAND_SET_CHANGED", "CMD_SCREEN_BASE", "ScreenSwitcher",
59
+ "Validator", "FilterValidator", "RangeValidator", "LookupValidator",
60
+ "StringLookupValidator", "PXPictureValidator",
61
+ ]
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2026 Peter Kokosharov <peter.kokosharov@gmail.com>
2
+ # SPDX-License-Identifier: MIT
3
+ # AI models: claude-opus-5-5
4
+ """Old names that keep working for one release, with a ``DeprecationWarning``.
5
+
6
+ ``renamed_arg`` is called at the top of a constructor that renamed a keyword
7
+ argument; ``renamed_attr`` makes a property that forwards an old attribute name
8
+ to the new one. Both say which name to use instead.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import warnings
14
+ from typing import Any
15
+
16
+ # Default of a deprecated keyword argument: "the caller did not pass it".
17
+ UNSET: Any = object()
18
+
19
+
20
+ def renamed_arg[T](owner: str, old: str, new: str, old_value: object, new_value: T) -> T:
21
+ """The value for ``new``: ``new_value``, or ``old_value`` (with a warning) when the
22
+ caller still used the old keyword. Passing both is a ``TypeError``.
23
+
24
+ Contract: the new keyword defaults to ``None`` (every renamed scroll-bar
25
+ argument does), so an explicit ``new=None`` counts as "not given" and the
26
+ old value is taken. Do not use this for an argument whose ``None`` means
27
+ something."""
28
+ if old_value is UNSET:
29
+ return new_value
30
+ if new_value is not None:
31
+ raise TypeError(f"{owner}() got both {old!r} and {new!r}; use {new!r}")
32
+ warnings.warn(f"{owner}({old}=...) is deprecated; use {new}=...",
33
+ DeprecationWarning, stacklevel=3)
34
+ return old_value # type: ignore[return-value]
35
+
36
+
37
+ def renamed_attr(owner: str, old: str, new: str) -> property:
38
+ """A read/write property ``old`` that warns and forwards to the attribute ``new``."""
39
+ message = f"{owner}.{old} is deprecated; use {owner}.{new}"
40
+
41
+ def get(self: object) -> Any:
42
+ warnings.warn(message, DeprecationWarning, stacklevel=2)
43
+ return getattr(self, new)
44
+
45
+ def put(self: object, value: object) -> None:
46
+ warnings.warn(message, DeprecationWarning, stacklevel=2)
47
+ setattr(self, new, value)
48
+
49
+ return property(get, put, doc=f"Deprecated alias of ``{new}``.")