Rename _CursesWindow to window (#5180)

* Rename _CursesWindow to window in Python >= 3.8

The name _CursesWindow is not exposed at runtime which makes explicit type annotation difficult. It has to be wrapped in quotes, and this doesn't seem to work for all type checkers: PyLance's typechecker accepts it but Jedi's doesn't (tested in VS Code). This is especially annoying because with curses.wrapper(callback) there is no way to infer the type of the passed window except with an explicit annotation.
Experimentally, the type is exposed under the name "_curses.window" in Python 3.9 on both Ubuntu and Windows (via [windows-curses](https://pypi.org/project/windows-curses/)). While this is not explicitly documented as public, it is the name used for all the window method docs, and it is probably unlikely to change since some might interpret the lack of underscore as indicating it is public. Unfortunately it doesn't seem to be exposed as such in Python 2, but `¯\_(ツ)_/¯`. Using the runtime name should allow type checking to work with most typecheckers/platforms without quotes, and the old name can be kept as an alias for backwards compatibility.

I discovered the name _curses.window is only actually exported in Python >= 3.8 so I moved the name behind a version check, and reverted the original class name to _CursesWindow

Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Ryan McCampbell
2021-04-05 16:59:37 -04:00
committed by GitHub
parent 2e703c37e9
commit 701e741946

View File

@@ -539,3 +539,4 @@ if sys.version_info >= (3, 8):
minor: int
patch: int
ncurses_version: _ncurses_version
window = _CursesWindow # undocumented