[pypy-commit] pypy py3.5: Move SimpleNamespace to lib_pypy, this avoids freezing the 'types' module,
amauryfa
pypy.commits at gmail.com
Mon Apr 17 15:16:53 EDT 2017
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.5
Changeset: r91067:34a763246fde
Date: 2017-04-17 15:27 +0200
http://bitbucket.org/pypy/pypy/changeset/34a763246fde/
Log: Move SimpleNamespace to lib_pypy, this avoids freezing the 'types'
module, and also 'functools', 'collections', 'weakref'...
diff --git a/lib_pypy/_structseq.py b/lib_pypy/_structseq.py
--- a/lib_pypy/_structseq.py
+++ b/lib_pypy/_structseq.py
@@ -129,3 +129,38 @@
parts = ["%s=%r" % (fields[index].__name__, value)
for index, value in enumerate(self[:visible_count])]
return "%s(%s)" % (self._name, ", ".join(parts))
+
+
+class SimpleNamespace:
+ """A simple attribute-based namespace.
+
+SimpleNamespace(**kwargs)"""
+
+ def __init__(self, **kwargs):
+ self.__dict__.update(kwargs)
+
+ def __repr__(self):
+ ident = id(self)
+ if ident in sns_recurse:
+ return "namespace(...)"
+ sns_recurse.add(ident)
+ try:
+ pairs = ('%s=%r' % item for item in sorted(self.__dict__.items()))
+ return "namespace(%s)" % ', '.join(pairs)
+ finally:
+ sns_recurse.discard(ident)
+
+ def __eq__(self, other):
+ if issubclass(type(other), SimpleNamespace):
+ return self.__dict__ == other.__dict__
+ return NotImplemented
+
+ def __ne__(self, other):
+ if issubclass(type(other), SimpleNamespace):
+ return self.__dict__ != other.__dict__
+ return NotImplemented
+
+sns_recurse = set()
+
+# This class is not exposed in sys, but by the types module.
+SimpleNamespace.__module__ = 'types'
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -3,7 +3,7 @@
The 'sys' module.
"""
-from _structseq import structseqtype, structseqfield
+from _structseq import structseqtype, structseqfield, SimpleNamespace
import sys
import _imp
@@ -111,41 +111,6 @@
null__xoptions = {}
-class SimpleNamespace:
- """A simple attribute-based namespace.
-
-SimpleNamespace(**kwargs)"""
-
- def __init__(self, **kwargs):
- self.__dict__.update(kwargs)
-
- def __repr__(self):
- ident = id(self)
- if ident in sns_recurse:
- return "namespace(...)"
- sns_recurse.add(ident)
- try:
- pairs = ('%s=%r' % item for item in sorted(self.__dict__.items()))
- return "namespace(%s)" % ', '.join(pairs)
- finally:
- sns_recurse.discard(ident)
-
- def __eq__(self, other):
- if issubclass(type(other), SimpleNamespace):
- return self.__dict__ == other.__dict__
- return NotImplemented
-
- def __ne__(self, other):
- if issubclass(type(other), SimpleNamespace):
- return self.__dict__ != other.__dict__
- return NotImplemented
-
-sns_recurse = set()
-
-# This class is not exposed in sys, but by the types module.
-SimpleNamespace.__module__ = 'types'
-
-
implementation = SimpleNamespace(
name='pypy',
version=sys.version_info,
diff --git a/pypy/module/time/app_time.py b/pypy/module/time/app_time.py
--- a/pypy/module/time/app_time.py
+++ b/pypy/module/time/app_time.py
@@ -1,7 +1,6 @@
# NOT_RPYTHON
-from _structseq import structseqtype, structseqfield
-from types import SimpleNamespace
+from _structseq import structseqtype, structseqfield, SimpleNamespace
import time
class struct_time(metaclass=structseqtype):
More information about the pypy-commit
mailing list