sugarlabs / sugar-toolkit-gtk3

Sugar Learning Environment, Activity Toolkit, GTK 3.
GNU Lesser General Public License v2.1
21 stars 80 forks source link

use xml.etree.ElementTree as xml.etree.CElementTree will be deprecated #448

Closed chimosky closed 4 years ago

chimosky commented 4 years ago

This is a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1817644

@nullr0ute @aperezbios

@quozl kindly review.

quozl commented 4 years ago

Thanks.

https://bugzilla.redhat.com/show_bug.cgi is a bad link?

On Python 3 we get ModuleNotFoundError not ImportError. Is the exception handler properly constructed to be both Python 2 and Python 3 compatible?

Can't we just replace the import with import xml.etree.ElementTree as ET?

chimosky commented 4 years ago

https://bugzilla.redhat.com/show_bug.cgi is a bad link?

Yeah, replaced that in my opening comment.

On Python 3 we get ModuleNotFoundError not ImportError. Is the exception handler properly constructed to be both Python 2 and Python 3 compatible?

Yeah, my bad.

Can't we just replace the import with import xml.etree.ElementTree as ET?

Yes we can just do that, I added the exception for convenience. I'll just import xml.etree.Elementree as ET.

quozl commented 4 years ago

8c976bd56a488d5612b1f69b24c45af114219079

encukou commented 4 years ago

On Python 3 we get ModuleNotFoundError not ImportError.

FWIW, ModuleNotFoundError is a subclass of ImportError, so except ImportError would handle both.

chimosky commented 4 years ago

On Python 3 we get ModuleNotFoundError not ImportError.

FWIW, ModuleNotFoundError is a subclass of ImportError, so except ImportError would handle both.

Yeah it should but for some reason, isinstance(ModuleNotFoundError, ImportError) returns False.

encukou commented 4 years ago

You want issubclass for classes.

>>> issubclass(ModuleNotFoundError, ImportError)
True
>>> isinstance(ModuleNotFoundError(), ImportError)  # note extra parentheses
True
>>> try:
...     raise ModuleNotFoundError
... except ImportError:
...     print('handled')
... 
handled
chimosky commented 4 years ago

You want issubclass for classes.

>>> issubclass(ModuleNotFoundError, ImportError)
True
>>> isinstance(ModuleNotFoundError(), ImportError)  # note extra parentheses
True
>>> try:
...     raise ModuleNotFoundError
... except ImportError:
...     print('handled')
... 
handled

Thanks