'Jython - Do these two boolean statements do the same thing?

I'm reasonably new to Python but I thought I understood how the flow control worked.

I'm pasting this from the Jython github at line 418

418: pkgname = globals.get('__package__')
419: if pkgname is not None:
420:     if not pkgname and level > 0:
421:         raise ValueError, 'Attempted relative import in non-package'

Does pkgname is not None on line 419 do the same thing as not pkgname on line 420? If it does, why would that check be there?

I'm reading the import source code so I can understand the system better and, though minor, this struck me as odd. As I'm still learning Python, I don't want to take anything for granted.

Thank you!



Solution 1:[1]

You are correct the second check for if not pkgname is not needed so the code can just be

418: pkgname = globals.get('__package__')
419: if pkgname is not None:
420:     if level > 0:
421:         raise ValueError, 'Attempted relative import in non-package'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harry_Hopkinson