bottle-react
bottle-react copied to clipboard
Do not silently swallow import errors in non-prod environments
try:
import jsx_props
self.default_props = jsx_props.__dict__.get('init%s'%name, dict)
except ImportError:
pass
Do not silently swallow import errors in non-prod environments.
defining jsx_props
is optional. what should we do if it's not there?
This was poorly explained. The idea was to separate finding jsx_props
and loading it so that we don't silence errors in jsx_props
itself.
I'm not sure what the best mechanism is, but something like this would work:
import importlib
jsx_props_exists = importlib.util.find_spec('jsx_props')
if jsx_props_exists:
import jsx_props
self.default_props = jsx_props.__dict__.get('init%s'%name, dict)
ah. yeah, that makes sense
it seems that python already does this:
$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bad
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bad.py", line 4
def ():
^
SyntaxError: invalid syntax
>>>
>>> import good
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named good
>>>
note the two different exception types
Not if the error in bad
is an ImportError
.
logan@logan-desktop:~/.../pyapp$ python
Python 3.5.3 (default, Nov 23 2017, 11:34:05)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bad
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/logan/.../pyapp/bad.py", line 1, in <module>
import idontexist
ImportError: No module named 'idontexist'
>>>
logan@logan-desktop:~/.../pyapp$ cat bad.py
import idontexist