Giter Club home page Giter Club logo

Comments (7)

nogayama avatar nogayama commented on September 9, 2024

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()

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

The workaround is

  • before
    params.get("color", "red").lower()
  • after
    (params.get("color", "red") or "red").lower()

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

But unfortunately there are too many params.get(key, default_value) in this tool. Fixing all lines by the workaround above is not realistic.

https://github.com/IBM/vision-tools/search?q=params.get%28

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

All params variables are instance of docopt.ParsedOptions(dict). So we may be able to fix this issue by hooking this class.

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

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

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

I opened a pull request with my solution #41. Please merge it.

from vision-tools.

nogayama avatar nogayama commented on September 9, 2024

@bcarld Thanks!

from vision-tools.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.