Skip to content

Input validations for alias command in pdb #111719

Closed
@gaogaotiantian

Description

@gaogaotiantian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions