Skip to content

Commit 0afde35

Browse files
authored
Merge pull request #536 from python/main
Sync Fork from Upstream Repo
2 parents ab53e04 + a045991 commit 0afde35

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Doc/library/symtable.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,5 @@ Examining Symbol Tables
194194

195195
.. method:: get_namespace()
196196

197-
Return the namespace bound to this name. If more than one namespace is
198-
bound, :exc:`ValueError` is raised.
197+
Return the namespace bound to this name. If more than one or no namespace
198+
is bound to this name, a :exc:`ValueError` is raised.

Include/internal/pycore_unionobject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
PyAPI_DATA(PyTypeObject) _PyUnion_Type;
11+
extern PyTypeObject _PyUnion_Type;
1212
#define _PyUnion_Check(op) Py_IS_TYPE(op, &_PyUnion_Type)
13-
PyAPI_FUNC(PyObject *) _Py_union_type_or(PyObject *, PyObject *);
13+
extern PyObject *_Py_union_type_or(PyObject *, PyObject *);
1414

1515
#define _PyGenericAlias_Check(op) PyObject_TypeCheck(op, &Py_GenericAliasType)
16-
PyAPI_FUNC(PyObject *) _Py_subs_parameters(PyObject *, PyObject *, PyObject *, PyObject *);
17-
PyAPI_FUNC(PyObject *) _Py_make_parameters(PyObject *);
16+
extern PyObject *_Py_subs_parameters(PyObject *, PyObject *, PyObject *, PyObject *);
17+
extern PyObject *_Py_make_parameters(PyObject *);
1818

1919
#ifdef __cplusplus
2020
}

Lib/symtable.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,15 @@ def get_namespaces(self):
306306
def get_namespace(self):
307307
"""Return the single namespace bound to this name.
308308
309-
Raises ValueError if the name is bound to multiple namespaces.
309+
Raises ValueError if the name is bound to multiple namespaces
310+
or no namespace.
310311
"""
311-
if len(self.__namespaces) != 1:
312+
if len(self.__namespaces) == 0:
313+
raise ValueError("name is not bound to any namespaces")
314+
elif len(self.__namespaces) > 1:
312315
raise ValueError("name is bound to multiple namespaces")
313-
return self.__namespaces[0]
316+
else:
317+
return self.__namespaces[0]
314318

315319
if __name__ == "__main__":
316320
import os, sys

Lib/test/test_symtable.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def test_namespaces(self):
159159
self.assertEqual(len(ns_test.get_namespaces()), 2)
160160
self.assertRaises(ValueError, ns_test.get_namespace)
161161

162+
ns_test_2 = self.top.lookup("glob")
163+
self.assertEqual(len(ns_test_2.get_namespaces()), 0)
164+
self.assertRaises(ValueError, ns_test_2.get_namespace)
165+
162166
def test_assigned(self):
163167
self.assertTrue(self.spam.lookup("x").is_assigned())
164168
self.assertTrue(self.spam.lookup("bar").is_assigned())

0 commit comments

Comments
 (0)