omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Ui.parse_color accepting anything input as valid

    Pythonista
    ui.parse.color
    2
    3
    1377
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Phuket2
      Phuket2 last edited by

      @omz as far as I can see ui.parse_color tries to accept any input. Meaning it does not fail. Maybe there is a fail flag in values I am not seeing. At first I thought it was defaulting to (0,0,0,1.0) if it had bad input, but that's not the case.
      Did you have a strategy in mind how to determine from the result that the passed parameter is invalid? In this case I am thinking more about css names.
      I can pass 'rxx' to ui._parse_color and still get a result. Just not the right result. I have the css names in .json formatted file. Just seems over kill to have to load it to see if a Css color name is valid or not.

      1 Reply Last reply Reply Quote 1
      • omz
        omz last edited by omz

        It intentionally never fails if the data type is correct (i.e. a number, tuple or string), but the error handling is buggy, as I just noticed, and the result is basically undefined in some cases. I think I'll change this to return (0, 0, 0, 0) as a default when there is no color with the given name. It might also make sense to return negative values, as that would never be a valid result, but I don't think I want this to throw exceptions.

        Phuket2 1 Reply Last reply Reply Quote 1
        • Phuket2
          Phuket2 @omz last edited by

          @omz , ok great. I think (0,0,0,0) is good. Can't image that would trip someone up on testing for a valid response and no exception thrown.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors