@@ -66,16 +66,20 @@ namespace_dealloc(_PyNamespaceObject *ns)
6666
6767
6868static PyObject *
69- namespace_repr (_PyNamespaceObject * ns )
69+ namespace_repr (PyObject * ns )
7070{
7171 int i , loop_error = 0 ;
7272 PyObject * pairs = NULL , * d = NULL , * keys = NULL , * keys_iter = NULL ;
7373 PyObject * key ;
7474 PyObject * separator , * pairsrepr , * repr = NULL ;
75+ const char * name ;
7576
76- i = Py_ReprEnter ((PyObject * )ns );
77+ name = (Py_TYPE (ns ) == & _PyNamespace_Type ) ? "namespace"
78+ : ns -> ob_type -> tp_name ;
79+
80+ i = Py_ReprEnter (ns );
7781 if (i != 0 ) {
78- return i > 0 ? PyUnicode_FromString ( "namespace (...)" ) : NULL ;
82+ return i > 0 ? PyUnicode_FromFormat ( "%s (...)", name ) : NULL ;
7983 }
8084
8185 pairs = PyList_New (0 );
@@ -127,16 +131,15 @@ namespace_repr(_PyNamespaceObject *ns)
127131 if (pairsrepr == NULL )
128132 goto error ;
129133
130- repr = PyUnicode_FromFormat ("%s(%S)" ,
131- ((PyObject * )ns )-> ob_type -> tp_name , pairsrepr );
134+ repr = PyUnicode_FromFormat ("%s(%S)" , name , pairsrepr );
132135 Py_DECREF (pairsrepr );
133136
134137error :
135138 Py_XDECREF (pairs );
136139 Py_XDECREF (d );
137140 Py_XDECREF (keys );
138141 Py_XDECREF (keys_iter );
139- Py_ReprLeave (( PyObject * ) ns );
142+ Py_ReprLeave (ns );
140143
141144 return repr ;
142145}
@@ -158,14 +161,26 @@ namespace_clear(_PyNamespaceObject *ns)
158161}
159162
160163
164+ static PyObject *
165+ namespace_richcompare (PyObject * self , PyObject * other , int op )
166+ {
167+ if (PyObject_IsInstance (self , (PyObject * )& _PyNamespace_Type ) &&
168+ PyObject_IsInstance (other , (PyObject * )& _PyNamespace_Type ))
169+ return PyObject_RichCompare (((_PyNamespaceObject * )self )-> ns_dict ,
170+ ((_PyNamespaceObject * )other )-> ns_dict , op );
171+ Py_INCREF (Py_NotImplemented );
172+ return Py_NotImplemented ;
173+ }
174+
175+
161176PyDoc_STRVAR (namespace_doc ,
162177"A simple attribute-based namespace.\n\
163178\n\
164- namespace (**kwargs)" );
179+ SimpleNamespace (**kwargs)" );
165180
166181PyTypeObject _PyNamespace_Type = {
167182 PyVarObject_HEAD_INIT (& PyType_Type , 0 )
168- "namespace" , /* tp_name */
183+ "types.SimpleNamespace" , /* tp_name */
169184 sizeof (_PyNamespaceObject ), /* tp_size */
170185 0 , /* tp_itemsize */
171186 (destructor )namespace_dealloc , /* tp_dealloc */
@@ -188,7 +203,7 @@ PyTypeObject _PyNamespace_Type = {
188203 namespace_doc , /* tp_doc */
189204 (traverseproc )namespace_traverse , /* tp_traverse */
190205 (inquiry )namespace_clear , /* tp_clear */
191- 0 , /* tp_richcompare */
206+ namespace_richcompare , /* tp_richcompare */
192207 0 , /* tp_weaklistoffset */
193208 0 , /* tp_iter */
194209 0 , /* tp_iternext */
0 commit comments