Show custom error message in prompt with hide_input=True#3256
Show custom error message in prompt with hide_input=True#3256doiken wants to merge 3 commits intopallets:mainfrom
hide_input=True#3256Conversation
hide_input=True
36a0bad to
3dac311
Compare
|
So exactly what I was thinking @AndreasBackx : this fix is way too naive. See the number of failing edge-cases I was able to add. So now: either I try to fix it locally on top of that PR, or I can implement a better long-term solution. Maybe by modifying how |
|
I've got two thoughts as well. We could instead of a ValueError do a custom error like you say, but require the message to be a literal meaning you cannot interpolate the input value in it. Or... we wrap the input value in a wrapper that has its own str and repr implementation that would obfuscate the real value. The real value would be some subfield perhaps. Though this would be a breaking change and I don't think it's very pretty. |
3dac311 to
3c2fc33
Compare
hide_input=Truehide_input=True
c5d2967 to
61bdc2a
Compare
I think the subfield looks like the ultimate, realiable solution. But it would introduce too much changes in my opinion. And I am not sure if it will look clean or not. I propose to defer that exploration in another PR. In the mean time, I implemented a solution based on regexp so the hidden heuristic is more robust and cover all cases. You can see the edge-cases I handle with this regexp in the associated unittests. Just pushed that on top of the PR. So this PR is ready to be reviewed and merged unless someone has feedbacks. |
|
Thanks so much for taking the time to push the regex-based solution and the extra test coverage! |
fixes #2809
prompt()withhide_input=Truealways showed a generic error message, even for custom types.This change masks the input value using
repr(value)matching(consistent with built-in types'
{value!r}pattern) and showscustom messages that don't contain the input value as-is.