django-bootstrap-studio-tools icon indicating copy to clipboard operation
django-bootstrap-studio-tools copied to clipboard

export.py : Avoid conditional check in for loops

Open AbcSxyZ opened this issue 5 years ago • 3 comments

You have the same useless condition in each loop : For exemple:

for div in soup.find_all(attrs={"dj-load": True}):
    if div:
        forline = "{% load " + div.get('dj-load') + " %}"
        div.insert_before(forline)
        del div

The if div condition make no sense, you will have a div for each loop, or won't go inside the for loop if it won't find anything. You can remove if condition for each loop.

AbcSxyZ avatar Aug 06 '20 22:08 AbcSxyZ

I did it quickly in https://github.com/lingster/django-bootstrap-studio-tools/pull/9

AbcSxyZ avatar Aug 06 '20 22:08 AbcSxyZ

ok, makes sense. However I think one of the problems with this script is that we don't have any test cases to verify if a particular change will continue to work or if something would break.

lingster avatar Aug 08 '20 08:08 lingster

For sure, it will be nice to have some test, but actually I've no idea how to perform it to check generated content. I'm not able to provide it, and if no one plan to do this and if you won't import PR until you have test, it will be hard to move on :)

In the same idea you're performing some check like :

if "dj-for" in div.attrs:

It's useless because you're selecting tag according to their attribute, so it must have dj-for in his attribute dict.

AbcSxyZ avatar Aug 08 '20 10:08 AbcSxyZ