Skip to content

bpo-33610: validate non-negative integer inputs in IDLE's config#14822

Merged
taleinat merged 2 commits into
python:masterfrom
taleinat:bpo-33610/IDLE-config-dialog-int-validation
Jul 23, 2019
Merged

bpo-33610: validate non-negative integer inputs in IDLE's config#14822
taleinat merged 2 commits into
python:masterfrom
taleinat:bpo-33610/IDLE-config-dialog-int-validation

Conversation

@taleinat
Copy link
Copy Markdown
Contributor

@taleinat taleinat commented Jul 17, 2019

This forces the entry widgets to always only contain digits or be empty.

https://bugs.python.org/issue33610

This forces the entry widgets to always only contain digits or
be empty.
Copy link
Copy Markdown
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the patch, I entered '15aa' for max context lines. When I closed and reopened config dialog, it only showed 15. 'OK, no damage done.' When I closed and restarted IDLE,
" Warning: config.py - IdleConf.GetOption -
invalid 'int' value for configuration option 'maxlines'
from section 'CodeContext': '15aa'

So I highly approve of adding something to prevent this in the next week (but see name comment).

It would be nice to check that an entry is in an allowed range, with an error message. I suspect that 0 for some entries could disable IDLE or at least have negative effects. But I have not tested my suggestion, limits would need some discussion, and it might be a good idea to put them in a global dict.

I mentioned not restricting validation to the General tab because I want to replace the indent slider with an Entry box. I would like to eventually move this to the first section of the General tab, but perhaps only when splitting that tab into two.

Comment thread Lib/idlelib/configdialog.py Outdated
def is_digits_or_empty(s):
"Return 's is blank or contains only digits'"
return digits_or_empty_re.fullmatch(s) is not None
self.digits_or_empty_vldcmd = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly prefer a simpler name, such as 'digits_only', or 'check_digits', or 'non_negative'.

Comment thread Lib/idlelib/configdialog.py
@taleinat
Copy link
Copy Markdown
Contributor Author

taleinat commented Jul 19, 2019

The trouble with range checks is that we shouldn't run them on every change, rejecting invalid changes, as we do with the "empty or digits only" check. Not allowing zero would be fine, because there's never a good reason to write a number with leading zeros in such a config dialog. But anything beyond that would make editing the value a hassle.

For example, if I wanted to change the default window width from 80 to 100, I couldn't delete the "80" and type "100" nor could I delete the "8" and add "10". I would have to do something like type "100" after the "80", resulting in "80100", and then delete the "80".

Assuming we agree that that is horrible UX, we'd need to validate the value on focus out and/or hitting the "apply" or "ok" buttons, and somehow inform the user which value(s) they've set are invalid and why. That's orders of magnitude more complex than what's needed for my suggestion above.

I suggest staying with the current method, making a few entries non-zero, and leaving the range checks for a separate issue.

@terryjreedy
Copy link
Copy Markdown
Member

terryjreedy commented Jul 19, 2019

You are right. A range validation should wait for a later event than key press in the widget. That includes checking for initial 0, as changing 80 to 0 to 90 would temporarily have a leading 0. (I guess this is why I put off range checks for 'later'.) So keep the current new check.

@taleinat taleinat merged commit 1ebee37 into python:master Jul 23, 2019
@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @taleinat for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@taleinat taleinat deleted the bpo-33610/IDLE-config-dialog-int-validation branch July 23, 2019 10:02
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2019
…honGH-14822)

(cherry picked from commit 1ebee37)

Co-authored-by: Tal Einat <taleinat@gmail.com>
@bedevere-bot
Copy link
Copy Markdown

GH-14913 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2019
…honGH-14822)

(cherry picked from commit 1ebee37)

Co-authored-by: Tal Einat <taleinat@gmail.com>
@bedevere-bot
Copy link
Copy Markdown

GH-14914 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Jul 23, 2019
…14822)

(cherry picked from commit 1ebee37)

Co-authored-by: Tal Einat <taleinat@gmail.com>
miss-islington added a commit that referenced this pull request Jul 23, 2019
…14822)

(cherry picked from commit 1ebee37)

Co-authored-by: Tal Einat <taleinat@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants