[PATCH] py3: handle os.environ() and os.environb() case

Yuya Nishihara yuya at tcha.org
Fri Sep 23 10:06:23 EDT 2016


On Fri, 23 Sep 2016 12:23:36 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1474613335 -19800
> #      Fri Sep 23 12:18:55 2016 +0530
> # Node ID 73e8bbaae1e350f6aa7b621cf29fcaba5d6508b5
> # Parent  85bd31515225e7fdf9bd88edde054db2c74a33f8
> py3: handle os.environ() and os.environb() case

> +class osenviron(object):
> +    def __init__(self):
> +        self.__dict__ = {}
> +
> +    def __getattr__(self, name):
> +        if sys.version_info[0] < 3:
> +            return getattr(os.environ, name)
> +        else:
> +            try:
> +                return getattr(os.environb, name)
> +            except AttributeError:  #Windows case
> +                pass #TODO: add windows case here

Why do we need a class just to forward attributes? I think the osenviron
wrapper is necessary only on Windows.

  if py2:
      osenviron = os.environ
  else:
      try:
          osenviron = os.environb
      except AttributeError:
          osenviron = wrapper(os.environ)

FWIW, the wrapper would need the encoding module, so we'll have to work around
import cycle in some way.


More information about the Mercurial-devel mailing list