[Sugar-devel] [PATCH 04/21 sugar-toolkit] PEP8 cleanup: don't use has_key()

Simon Schampijer simon at schampijer.de
Fri Oct 29 06:30:47 EDT 2010


On 10/15/2010 11:01 PM, Sascha Silbe wrote:
> has_key() has been deprecated for quite some time now.
[...]
> diff --git a/src/sugar/graphics/style.py b/src/sugar/graphics/style.py
> index 2828b7f..d5f82ff 100644
> --- a/src/sugar/graphics/style.py
> +++ b/src/sugar/graphics/style.py
> @@ -35,12 +35,11 @@ _TAB_CURVATURE = 1
>
>
>   def _compute_zoom_factor():
> -    if os.environ.has_key('SUGAR_SCALING'):
> -        try:
> -            scaling = int(os.environ['SUGAR_SCALING'])
> -            return scaling / 100.0
> -        except ValueError:
> -            logging.error('Invalid SUGAR_SCALING.')
> +    try:
> +        scaling = int(os.environ.get('SUGAR_SCALING', '100'))
> +        return scaling / 100.0
> +    except ValueError:
> +        logging.error('Invalid SUGAR_SCALING.')
>
>       return 1.0

I prefer to only have in the try block what you want to look for. You 
can use else for the return. For readability I would actually keep the 
verbose form. First check for the key, then do the rest.

> diff --git a/src/sugar/network.py b/src/sugar/network.py
> index bde8c9f..b72acad 100644
> --- a/src/sugar/network.py
> +++ b/src/sugar/network.py
> @@ -242,7 +242,7 @@ class GlibURLDownloader(gobject.GObject):
>           self.cleanup(remove=True)
>
>       def _get_filename_from_headers(self, headers):
> -        if not headers.has_key("Content-Disposition"):
> +        if 'Content-Disposition' not in headers:
>               return None
>
>           ftag = "filename="
> --
> 1.7.1
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


The rest looks good.

Thanks,
    Simon


More information about the Sugar-devel mailing list