Skip to content

Input validations for alias command in pdb #111719

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

Closed
gaogaotiantian opened this issue Nov 4, 2023 · 1 comment
Closed

Input validations for alias command in pdb #111719

gaogaotiantian opened this issue Nov 4, 2023 · 1 comment
Labels
type-feature A feature request or enhancement

Comments

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Nov 4, 2023

Feature or enhancement

Proposal:

This is kind of between a bug and a feature. alias, admittedly a rarely used command, is very unpolished.

The documentation claimed

Replaceable parameters can be indicated by %1, %2, and so on

But that's not the truth, %10 will not work because it contains %1 and we are using pure string replacement. I doubt anyone would need %10 so I just updated the document to imply that we only support up to %9.

All the replaceable parameters should be consecutive as well, if %* does not exist. I can't find one reason where an alias needs parameter 1 and 3, but not 2. (Feel free to show a useful example if you can think of one). We should catch this because it's almost definitely a mistake made by users.

When using alias, we should match all the replaceable parameters and the user input arguments if %* does not exist, otherwise something has to be wrong and we should warn user.

I stepped into this today when I was trying to use alias for some testing:

(Pdb) alias myp p
(Pdb) myp 1
*** SyntaxError: invalid syntax
(Pdb) 

Really confusing huh? What if it's

(Pdb) alias myp p
(Pdb) myp 1
*** Too many arguments for alias 'myp'
(Pdb) 

It'll probably be easier to track the logic and make you realize that there's no replaceable parameters defined in myp and it should be alias myp %1.

It's not the most intuitive way but it has been there for a long time. Making the error message better will hopefully make users less confusing.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@hugovk
Copy link
Member

hugovk commented Nov 9, 2023

Closing because #111720 has been merged. Feel free to re-open if more needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants