diff mbox series

[1/1] python/semanage: fix Python syntax of catching several exceptions

Message ID 20180804091147.19092-1-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show
Series [1/1] python/semanage: fix Python syntax of catching several exceptions | expand

Commit Message

Nicolas Iooss Aug. 4, 2018, 9:11 a.m. UTC
"except OSError, ImportError:" does not perform what it says: it is the
Python 2 syntax of catching OSError exceptions as "ImportError" (like
"except OSError, e:"), and this is indeed caught by Python3:

      File "./python/semanage/seobject.py", line 143
        except OSError, ImportError:
                      ^
    SyntaxError: invalid syntax

The correct syntax consists in using parentheses.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
For the record, I found this while playing with flake8 Python's linter.
I am currently working on upstreaming a script which would run this on
our Travis-CI environment in order to catch Python syntax errors before
they are introduced.

 python/semanage/seobject.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Zaman Aug. 4, 2018, 9:34 a.m. UTC | #1
On Sat, Aug 04, 2018 at 11:11:47AM +0200, Nicolas Iooss wrote:
> "except OSError, ImportError:" does not perform what it says: it is the
> Python 2 syntax of catching OSError exceptions as "ImportError" (like
> "except OSError, e:"), and this is indeed caught by Python3:
> 
>       File "./python/semanage/seobject.py", line 143
>         except OSError, ImportError:
>                       ^
>     SyntaxError: invalid syntax
> 
> The correct syntax consists in using parentheses.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Acked-by: Jason Zaman <jason@perfinion.com>


> ---
> For the record, I found this while playing with flake8 Python's linter.
> I am currently working on upstreaming a script which would run this on
> our Travis-CI environment in order to catch Python syntax errors before
> they are introduced.

Awesome! more linters are always good. I really do need to find the time
to kill seobject more thoroughly tho, its so slow compared to direct
setools. :(

-- Jason

> 
>  python/semanage/seobject.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index 78ffb091ad2f..c14671855049 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -140,7 +140,7 @@ try:
>  
>              self.log_list = []
>              self.log_change_list = []
> -except OSError, ImportError:
> +except (OSError, ImportError):
>      class logger:
>  
>          def __init__(self):
> -- 
> 2.18.0
> 
> _______________________________________________
> Selinux mailing list
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to Selinux-request@tycho.nsa.gov.
Nicolas Iooss Aug. 4, 2018, 12:16 p.m. UTC | #2
On Sat, Aug 4, 2018 at 11:34 AM, Jason Zaman <jason@perfinion.com> wrote:
> On Sat, Aug 04, 2018 at 11:11:47AM +0200, Nicolas Iooss wrote:
>> "except OSError, ImportError:" does not perform what it says: it is the
>> Python 2 syntax of catching OSError exceptions as "ImportError" (like
>> "except OSError, e:"), and this is indeed caught by Python3:
>>
>>       File "./python/semanage/seobject.py", line 143
>>         except OSError, ImportError:
>>                       ^
>>     SyntaxError: invalid syntax
>>
>> The correct syntax consists in using parentheses.
>>
>> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>
> Acked-by: Jason Zaman <jason@perfinion.com>

Thanks. I will wait one business day before merging this (in order to
let other developers the possibility to comment, even though this
change is trivial).

>> ---
>> For the record, I found this while playing with flake8 Python's linter.
>> I am currently working on upstreaming a script which would run this on
>> our Travis-CI environment in order to catch Python syntax errors before
>> they are introduced.
>
> Awesome! more linters are always good. I really do need to find the time
> to kill seobject more thoroughly tho, its so slow compared to direct
> setools. :(

The more I look into flake8, the more I want to make it integrated to
our review process... I will send a few patches later today in order
to fix issues that it found in the Python code (for example "procotol"
instead of "protocol" in sepolicy/gui.py).

Cheers,
Nicolas
Nicolas Iooss Aug. 6, 2018, 8:08 p.m. UTC | #3
On Sat, Aug 4, 2018 at 2:16 PM, Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
> On Sat, Aug 4, 2018 at 11:34 AM, Jason Zaman <jason@perfinion.com> wrote:
>> On Sat, Aug 04, 2018 at 11:11:47AM +0200, Nicolas Iooss wrote:
>>> "except OSError, ImportError:" does not perform what it says: it is the
>>> Python 2 syntax of catching OSError exceptions as "ImportError" (like
>>> "except OSError, e:"), and this is indeed caught by Python3:
>>>
>>>       File "./python/semanage/seobject.py", line 143
>>>         except OSError, ImportError:
>>>                       ^
>>>     SyntaxError: invalid syntax
>>>
>>> The correct syntax consists in using parentheses.
>>>
>>> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>>
>> Acked-by: Jason Zaman <jason@perfinion.com>
>
> Thanks. I will wait one business day before merging this (in order to
> let other developers the possibility to comment, even though this
> change is trivial).

I applied this patch.
Nicolas
diff mbox series

Patch

diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index 78ffb091ad2f..c14671855049 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -140,7 +140,7 @@  try:
 
             self.log_list = []
             self.log_change_list = []
-except OSError, ImportError:
+except (OSError, ImportError):
     class logger:
 
         def __init__(self):