Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Useless if statement in yum source [closed]

Tags:

python

yum

I was curious about how something worked in yum so I was looking at some of its score code and I found this line in the erasePkgs function in cli.py.

if False: pass
elif basecmd in ('erase-n', 'remove-n'):
   rms = self.remove(name=arg)
.
.
.

The if False: pass does nothing correct? It never gets into that branch it always just skips to the next one doesn't it?

Here is the link to the source code: https://github.com/rpm-software-management/yum/blob/master/cli.py. It's on line 1268.

like image 875
Willwsharp Avatar asked Nov 08 '18 19:11

Willwsharp


People also ask

How do I know if my server is registered with satellite?

Ans: From the server's terminal run the command “subscription-manager status”, it will display the current subscription status and we can also verify the subscription status from Satellite dashboard, Go to the hosts Tab –> then content hosts –> See the subscription details.

How do I disable a yum repository?

To disable a particular repository or repositories, run the following command as the root user: yum-config-manager --disable repository… Alternatively, you can use a global regular expression to disable all matching Yum repositories: yum-config-manager --disable glob_expression…


1 Answers

This appears to be the developer's idiom for a generalized switch statement.

        if False: pass
        elif basecmd in ('erase-n', 'remove-n'):
            rms = self.remove(name=arg)
        elif basecmd in ('erase-na', 'remove-na'):
            ...
        elif basecmd in ('erase-nevra', 'remove-nevra'):
            ...
        else:
            ...

which is ever so slightly more readable than

        if basecmd in ('erase-n', 'remove-n'):
            rms = self.remove(name=arg)
        elif basecmd in ('erase-na', 'remove-na'):
            ...
        elif basecmd in ('erase-nevra', 'remove-nevra'):
            ...
        else:
            ...
like image 146
mjhm Avatar answered Sep 23 '22 22:09

mjhm