-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved termui.pause()
Function and Simplified Imports
#2774
Conversation
1. Set a default message ("Press any key to continue...") for the info parameter in the pause() function. This simplifies the function's use by providing a default without requiring explicit checks for a None value 2. Refactor the (pause()) function to remove redundant checks and simplify the control flow, improving readability while maintaining the existing functionality. 3. Simplify imports to avoid clutter.
Simplfied imports to improved readability and avoid clutter.
@@ -771,16 +773,11 @@ def pause(info: str | None = None, err: bool = False) -> None: | |||
if not isatty(sys.stdin) or not isatty(sys.stdout): | |||
return | |||
|
|||
if info is None: | |||
info = _("Press any key to continue...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here for translation, which must happen dynamically, not in the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOW IT MAKES SENSE!
This makes me feel terrible about it😅
@@ -227,6 +225,10 @@ def confirm( | |||
"y/n" if default is None else ("Y/n" if default else "y/N"), | |||
) | |||
|
|||
# Initialise rv to avoid a | |||
# `variable might be referenced before assignment` warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh?, I added that because I was seeing a warning in Pycharm
@@ -338,7 +338,7 @@ def __init__( | |||
max_content_width = parent.max_content_width | |||
|
|||
#: The maximum width of formatted content (None implies a sensible | |||
#: default which is 80 for most things). | |||
#: default whih is 80 for most things). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
@@ -17,6 +17,7 @@ | |||
from io import StringIO | |||
from types import TracebackType | |||
|
|||
# Imports can be simplified to improved readability and avoid clutter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style is deliberate and enforced by our formatting configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Okay, thanks :)
Thanks for your interest. However, we generally don't accept general refactors or style changes from outside contributors.
They indicate that the names are re-exported for type checkers and formatters. And the style used is deliberate, as enforced by our formatter. |
This pull request includes two main changes:
Pause Function Update:
termui.pause()
function has been improved by adding the default message ("Press any key to continue...") directly in the info param. This change improves readability and eliminates unnecessary checks for theinfo
paramif info
checks sinceinfo
will now have a default string value.Simplified Import Statements:
_compat
,exceptions
,types
, and other modules have been simplified.Quick Question:
I noticed these imports here:
Is there a reason for using
as
when the names are the same?I’m curious if there’s a specific reason for doing it this way, or if it’s something that could be simplified like so:
Just want to understand the thought process behind it!