xapi-project / xen-api

The Xapi Project's XenAPI Server
http://xenproject.org/developers/teams/xapi.html
Other
346 stars 283 forks source link

shell.py: Fix warnings caused by overwriting cmd with str, and str too. #5697

Closed bernhardkaindl closed 3 months ago

bernhardkaindl commented 3 months ago

@ashwin9390 @stephenchengCloud

A function in scripts/examples/python/shell.py overwrites the module cmd with a str, which results in these (not immediately obvious) warnings:

pytype: attribute-error: scripts/examples/python/shell.py#L36                                                                                                  
File "scripts/examples/python/shell.py", line 36, in __init__: No attribute 'Cmd' on str [attribute-error]
  In Union[module, str]
File "scripts/examples/python/shell.py", line 41, in preloop: No attribute 'Cmd' on str [attribute-error]
  In Union[module, str]

Let's fix it by not overwriting the module cmd, by naming the variable command instead of cmd:

cmd and command in the file after the change:

# grep -e 'cmd\>' -e command scripts/examples/python/shell.py
import cmd
class Shell(cmd.Cmd):
        cmd.Cmd.__init__(self)
        cmd.Cmd.preloop(self)
    # We want to support directly executing the cmd line,
        command = sys.argv[cmdAt]
            print(session.xenapi_request(command, tuple(params)), file=sys.stdout)

This makes it clear that with this change, from cmd to command for the last two lines, the conflict is resolved.

psafont commented 3 months ago

Shouldn't the script be moved into python3/?

bernhardkaindl commented 3 months ago

Pau asked:

Shouldn't the script be moved into python3/?

Of course, @ashwin9390 created CP-49926 for moving it into python3/ (and ~30 sibling tickets). I did not want to interfere with the order in which he wants to move all of them.

I also added now: