[stdlib-sig] proposed removal: the types module

Jeffrey Yasskin jyasskin at gmail.com
Fri Apr 4 18:16:28 CEST 2008


On Thu, Apr 3, 2008 at 10:14 AM, Facundo Batista
<facundobatista at gmail.com> wrote:
> 2008/4/3, Jeffrey Yasskin <jyasskin at gmail.com>:
>
>
>  > Just to pick one, try "type(...)". It's generally clearer to take an
>  >  example of what you want and ask for its type, than to look in the
>  >  types module.
>
>  How?
>
>  For example, I have this very complex class:
>
>  >>> class C:
>  ...     def met(self):
>  ...             pass
>  ...
>  >>> c = C()
>
>
>  I want, from outside to create a new method in it. So, I do the following:
>
>  >>> t = type(c.met)
>  >>> t()
>  Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>  TypeError: method expected 2 arguments, got 0
>
>
>  Ouch, it wasn't so easy. I realize myself I need to read the docs.
>  Where should I look for those docs and/or examples?

If you're just looking for a place to stash the documentation,
http://docs.python.org/dev/3.0/library/stdtypes.html#other-built-in-types
looks appropriate.

But looking at Steven's question made me change my mind. It's true
that types.CodeType can be replaced by
type(any_user_defined_function.__code__), but it makes me nervous to
assume that all code objects will always be exactly the same type.
Having a name in a standard place seems more reliable.

-- 
Namasté,
Jeffrey Yasskin


More information about the stdlib-sig mailing list