Discussion:
[Python-3000-checkins] r65897 - in python/branches/py3k: Doc/library/symtable.rst Lib/symtable.py Lib/test/test_symtable.py Misc/NEWS
benjamin.peterson
2008-08-20 02:06:00 UTC
Permalink
Author: benjamin.peterson
Date: Wed Aug 20 04:06:00 2008
New Revision: 65897

Log:
return sets instead of tuples from some symtable methods

Modified:
python/branches/py3k/Doc/library/symtable.rst
python/branches/py3k/Lib/symtable.py
python/branches/py3k/Lib/test/test_symtable.py
python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Doc/library/symtable.rst
==============================================================================
--- python/branches/py3k/Doc/library/symtable.rst (original)
+++ python/branches/py3k/Doc/library/symtable.rst Wed Aug 20 04:06:00 2008
@@ -95,19 +95,19 @@

.. 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
@@ -116,7 +116,7 @@

.. 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

Modified: python/branches/py3k/Lib/symtable.py
==============================================================================
--- python/branches/py3k/Lib/symtable.py (original)
+++ python/branches/py3k/Lib/symtable.py Wed Aug 20 04:06:00 2008
@@ -129,8 +129,8 @@
__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:
@@ -165,7 +165,7 @@
d = {}
for st in self._table.children:
d[st.name] = 1
- self.__methods = tuple(d)
+ self.__methods = frozenset(d)
return self.__methods



Modified: python/branches/py3k/Lib/test/test_symtable.py
==============================================================================
--- python/branches/py3k/Lib/test/test_symtable.py (original)
+++ python/branches/py3k/Lib/test/test_symtable.py Wed Aug 20 04:06:00 2008
@@ -80,11 +80,11 @@

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())
@@ -142,7 +142,7 @@
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

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Wed Aug 20 04:06:00 2008
@@ -249,6 +249,9 @@
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.
Nick Coghlan
2008-08-20 09:36:25 UTC
Permalink
Post by benjamin.peterson
Author: benjamin.peterson
Date: Wed Aug 20 04:06:00 2008
New Revision: 65897
return sets instead of tuples from some symtable methods
What are you gaining by throwing away the ordering information? That can
matter, especially for the parameters. If the symtable module itself has
already thrown away the ordering information by this point, then that in
itself is probably a bug to be fixed.

Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
Benjamin Peterson
2008-08-20 12:44:01 UTC
Permalink
Post by Nick Coghlan
Post by benjamin.peterson
Author: benjamin.peterson
Date: Wed Aug 20 04:06:00 2008
New Revision: 65897
return sets instead of tuples from some symtable methods
What are you gaining by throwing away the ordering information? That can
matter, especially for the parameters. If the symtable module itself has
already thrown away the ordering information by this point, then that in
itself is probably a bug to be fixed.'
That's a good point. Consider it reverted.
Post by Nick Coghlan
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000-checkins mailing list
Python-3000-checkins at python.org
http://mail.python.org/mailman/listinfo/python-3000-checkins
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
Loading...