bpo-42355: symtable.get_namespace() now checks whether there are multiple or any namespaces found by isidentical · Pull Request #23278 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/symtable.rst
10 changes: 7 additions & 3 deletions Lib/symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,15 @@ def get_namespaces(self):
def get_namespace(self):
"""Return the single namespace bound to this name.

Raises ValueError if the name is bound to multiple namespaces.
Raises ValueError if the name is bound to multiple namespaces
or no namespace.
"""
if len(self.__namespaces) != 1:
if len(self.__namespaces) == 0:
raise ValueError("name is not bound to any namespaces")
elif len(self.__namespaces) > 1:
raise ValueError("name is bound to multiple namespaces")
return self.__namespaces[0]
else:
return self.__namespaces[0]

if __name__ == "__main__":
import os, sys
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_symtable.py