Closed nogayama closed 3 years ago
If we store None
as value of dict, we face this error.
$ ipython
Python 3.9.1 (default, Feb 12 2021, 17:20:20)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: d = {"a": 10, "b": None}
In [2]: d.get("a", "red")
Out[2]: 10
In [3]: d.get("b", "red") is None
Out[3]: True
In [4]: d.get("c", "red")
Out[4]: 'red'
In [5]: d.get("b", "red").lower()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-5a428f4cd3b2> in <module>
----> 1 d.get("b", "red").lower()
The workaround is
params.get("color", "red").lower()
(params.get("color", "red") or "red").lower()
But unfortunately there are too many params.get(key, default_value)
in this tool. Fixing all lines by the workaround above is not realistic.
All params
variables are instance of docopt.ParsedOptions(dict)
. So we may be able to fix this issue by hooking this class.
I found a fundamental solution for this issue.
We can check the return value by overriding get
method of ParsedOptions
.
class ParsedOptions(dict):
...
def get(self, key, default_value=None):
if key in self:
value = super().get(key)
if value is not None:
return value
return default_value
I opened a pull request with my solution #41. Please merge it.
@bcarld Thanks!
Symptom
AttributeError when executing
vision deployed-models infer --annotatefile FILE
reproduce