[Python-checkins] Why? Re: r53925 - sandbox/trunk/pep362/pep362.py

Jim Jewett jimjjewett at gmail.com
Mon Feb 26 19:31:51 CET 2007


Why are you removing the __str__ function?

For me,

(1)  one of the more frustrating parts of the introspection API is
that you can't (easily) use it to create a new "similar" function.

(2)  one of the main uses of introspection is seeing what I have --
and "equivalent" source code is a useful output format.



On 2/25/07, brett.cannon <python-checkins at python.org> wrote:
> Author: brett.cannon
> Date: Sun Feb 25 23:59:37 2007
> New Revision: 53925
>
> Modified:
>    sandbox/trunk/pep362/pep362.py
> Log:
> Remove __str__ support.
>
>
> Modified: sandbox/trunk/pep362/pep362.py
> ==============================================================================
> --- sandbox/trunk/pep362/pep362.py      (original)
> +++ sandbox/trunk/pep362/pep362.py      Sun Feb 25 23:59:37 2007
> @@ -49,27 +49,6 @@
>              self.has_annotation = True
>              self.annotation = annotation
>
> -    def _tuple2param(self, tuple_):
> -        if not isinstance(tuple_, tuple):
> -            return str(tuple_)
> -        elif len(tuple_) == 1:
> -            return "(" + str(tuple_[0]) +",)"
> -        else:
> -            return ('(' +
> -                    ', '.join(self._tuple2param(x) for  x in tuple_) +
> -                    ')')
> -
> -    def __str__(self):
> -        """Return the string representation of the parameter as it would look
> -        in a function's signature."""
> -        if isinstance(self.name, tuple):
> -            result = self._tuple2param(self.name)
> -        else:
> -            result = self.name
> -        if self.has_default:
> -            result+= "=" + str(self.default_value)
> -        return result
> -
>
>  class Signature(object):
>
> @@ -92,7 +71,8 @@
>              keyword_only_count = func_code.co_kwonlyargcount
>          else:
>              keyword_only_count = 0
> -        positional = func_code.co_varnames[:pos_count]
> +        #positional = func_code.co_varnames[:pos_count]
> +        positional = argspec[0]
>          keyword_only = func_code.co_varnames[pos_count:keyword_only_count]
>          if func.func_defaults:
>              pos_default_count = len(func.func_defaults)
> @@ -178,22 +158,6 @@
>          else:
>              return tuple(cls._list2tuple(x) for x in list_)
>
> -    def __str__(self):
> -        """String representation of a signature as one might write it in source
> -        code."""
> -        result = "%s(" % self.name
> -        result += ", ".join(str(param) for param in self.parameters)
> -        if self.var_args:
> -            if self.parameters:
> -                result +=", "
> -            result += "*%s" % self.var_args
> -        if self.var_kw_args:
> -            if self.parameters or self.var_args:
> -                result += ", "
> -            result += "**%s" % self.var_kw_args
> -        result += ")"
> -        return result
> -
>      def bind(self, *args, **kwargs):
>          """Return a dictionary mapping function arguments to their parameter
>          variables, if possible.
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-checkins mailing list