diff options
author | Batuhan Taskaya <batuhan@python.org> | 2021-07-18 15:56:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-18 15:56:09 +0300 |
commit | a045991f60b51636a784623dda7ad84b5b2c6b73 (patch) | |
tree | 3b778d4c70034327e1066aee0060638d93ce11ad /Lib/symtable.py | |
parent | bpo-44654: Do not export the union type related symbols (GH-27223) (diff) | |
download | cpython-a045991f60b51636a784623dda7ad84b5b2c6b73.tar.gz cpython-a045991f60b51636a784623dda7ad84b5b2c6b73.tar.bz2 cpython-a045991f60b51636a784623dda7ad84b5b2c6b73.zip |
bpo-42355: symtable.get_namespace() now checks whether there are multiple or any namespaces found (GH-23278)
Diffstat (limited to 'Lib/symtable.py')
-rw-r--r-- | Lib/symtable.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py index 922854bf669..75ff0921f4c 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -306,11 +306,15 @@ class Symbol: 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 |