1. Armin Rigo
  2. cpython-withatomic

Commits

Benjamin Peterson  committed 3a11e79

return sets instead of tuples from some symtable methods

  • Participants
  • Parent commits 6cd7b18
  • Branches default

Comments (0)

Files changed (4)

File Doc/library/symtable.rst

View file
  • Ignore whitespace
 
    .. method:: get_parameters()
 
-      Return a tuple containing names of parameters to this function.
+      Return a set containing names of parameters to this function.
 
    .. method:: get_locals()
 
-      Return a tuple containing names of locals in this function.
+      Return a set containing names of locals in this function.
 
    .. method:: get_globals()
 
-      Return a tuple containing names of globals in this function.
+      Return a set containing names of globals in this function.
 
    .. method:: get_frees()
 
-      Return a tuple containing names of free variables in this function.
+      Return a set containing names of free variables in this function.
 
 
 .. class:: Class
 
    .. method:: get_methods()
 
-      Return a tuple containing the names of methods declared in the class.
+      Return a set containing the names of methods declared in the class.
 
 
 .. class:: Symbol

File Lib/symtable.py

View file
  • Ignore whitespace
     __globals = None
 
     def __idents_matching(self, test_func):
-        return tuple([ident for ident in self.get_identifiers()
-                      if test_func(self._table.symbols[ident])])
+        return frozenset(ident for ident in self.get_identifiers()
+                         if test_func(self._table.symbols[ident]))
 
     def get_parameters(self):
         if self.__params is None:
             d = {}
             for st in self._table.children:
                 d[st.name] = 1
-            self.__methods = tuple(d)
+            self.__methods = frozenset(d)
         return self.__methods
 
 

File Lib/test/test_symtable.py

View file
  • Ignore whitespace
 
     def test_function_info(self):
         func = self.spam
-        self.assertEqual(func.get_parameters(), ("a", "b", "kw", "var"))
+        self.assertEqual(func.get_parameters(), {"a", "b", "kw", "var"})
         self.assertEqual(func.get_locals(),
-                         ("a", "b", "bar", "glob", "internal", "kw", "var", "x"))
-        self.assertEqual(func.get_globals(), ("bar", "glob"))
-        self.assertEqual(self.internal.get_frees(), ("x",))
+                         {"a", "b", "bar", "glob", "internal", "kw", "var", "x"})
+        self.assertEqual(func.get_globals(), {"bar", "glob"})
+        self.assertEqual(self.internal.get_frees(), {"x"})
 
     def test_globals(self):
         self.assertTrue(self.spam.lookup("glob").is_global())
         self.assertEqual(self.Mine.get_name(), "Mine")
 
     def test_class_info(self):
-        self.assertEqual(self.Mine.get_methods(), ('a_method',))
+        self.assertEqual(self.Mine.get_methods(), {'a_method'})
 
     def test_filename_correct(self):
         ### Bug tickler: SyntaxError file name correct whether error raised

File Misc/NEWS

View file
  • Ignore whitespace
 Library
 -------
 
+- symtable.Function's ``get_locals()``, ``get_globals()``, ``get_parameters()``,
+  and ``get_frees()`` and symtable.Class's ``get_methods()`` now return sets.
+
 - The methods ``is_in_tuple()``, ``is_vararg()``, and ``is_keywordarg()`` of
   symtable.Symbol have been removed.