[PATCHv2] Read /etc/os-release to get product title (#1000426)

Vratislav Podzimek vpodzime at redhat.com
Fri Sep 6 07:04:04 UTC 2013


On Thu, 2013-09-05 at 14:22 -0700, Brian C. Lane wrote:
> > +def product_title():
> > +    """
> > +    Get product title.
> > +
> > +    :return: product title
> > +    :rtype: str
> > +
> > +    """
> > +
> > +    try:
> > +        with open(RELEASE_STRING_FILE, "r") as fobj:
> > +            for line in fobj:
> > +                (key, _eq, value) = line.strip().partition("=")
> > +                if not key or not _eq or not value:
> > +                    continue
> > +                if key == "PRETTY_NAME":
> > +                    return value.strip('"')
> > +    except IOError:
> > +        return ""
> 
> It says the return type is str, so it should return "" at the end
> instead of dropping out with None. Maybe something like:
> 
> except IOError:
>     pass
> finally:
>     return ""
I moved the 'return ""' statement out of the finally block because
pylint pointed out an interesting thing -- return statement in the
finally block swallows exceptions! It might not be a problem in this
case, but it's better not to play such game. :)

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list