Rename _CursesWindow to window - #5180
Merged
Merged
Conversation
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
Contributor
Author
|
Turns out the name _curses.window is only exposed in >= 3.8, so I put the new name behind a version test and reverted to the old name everywhere else. |
Akuli
requested changes
Apr 5, 2021
Co-authored-by: Akuli <[email protected]>
Akuli
approved these changes
Apr 5, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The name
_CursesWindowis 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 withcurses.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.windowin Python 3.9 on both Ubuntu and Windows (via windows-curses). While this is not explicitly documented as public, it is the name used for all the 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.