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

Brett Cannon bcannon at gmail.com
Mon Feb 26 21:40:47 CET 2007


On 2/26/07, Guido van Rossum <guido at python.org> wrote:
> On 2/26/07, Brett Cannon <bcannon at gmail.com> wrote:
> > On 2/26/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> > > Why are you removing the __str__ function?
> > >
> >
> > Because annotations prevent an accurate representation.  How do you
> > get int to display as 'int'?
>
> By changing type.__str__ to return self.__name__? I would be open to
> considering this.
>

Guido said that we can do this if Anthony likes it for either __str__
or __repr__.  What do you think, Anthony?

-Brett




> > > 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.
> > >
> >
> > I undderstand; I put in the method for a reason.  But if I can't have
> > it properly display all information then I don't want to have to
> > support a partial implementation.
> >
> > -Brett
> >
> > >
> > >
> > > 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
> > > >
> > > _______________________________________________
> > > Python-checkins mailing list
> > > Python-checkins at python.org
> > > http://mail.python.org/mailman/listinfo/python-checkins
> > >
> > _______________________________________________
> > Python-checkins mailing list
> > Python-checkins at python.org
> > http://mail.python.org/mailman/listinfo/python-checkins
> >
>
>
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
>


More information about the Python-checkins mailing list