[Python-3000] Fwd: proposal: disambiguating type
tomer filiba
tomerfiliba at gmail.com
Tue May 23 21:38:24 CEST 2006
Guido writes:
> Perhaps less code would break
> if you renamed the metaclass instead of the inquiry function.
hrrm... well, the only name, other than "type", that i could think of the
metaclass is "metalcass". for example,
class MyMetaclass(metaclass):
def __new__(cls, name, bases, dict):
dict["blah"] = 5
return metaclass.__new__(cls, name, bases, dict)
which seems okay. but the problem arises with type(),
which becomes a function --
>>> type(1)
<metaclass 'int'>
>>> type(list)
<metaclass 'metaclass'>
>>> type(metaclass)
<metaclass 'metaclass'>
>>> type(type)
<metaclass 'builtin_function_or_method'>
ugh?
metalcasses are a scary concept by themselves... the type of the
type... it's not quite /intuitive/ to newcommers. and it's not like
experienced programmers write metaclasses on a daily basis.
they are only used here and there.
yeah, i read the breastfeeding thread, but still, if i were a newcommer
and saw type(int) returned <metaclass>, i would ask myself
"wtf is a metaclass?", and start pulling my hair off.
metaclasses are not an everyday mechanism, and thus should be
"hidden" or kept out of everyday programming. on the other hand,
the concept of "type" more intuitive/common from other languages:
"the type of 4 is the integer type", as opposed to
"the type of 4 is the integer metaclass"
and since i read about plans for a mechanical tool that converts
legacy python code to py3k, i don't see how the amout of broken
code matters, as long as the code is converted right.
so i'd vote for type -> the metaclass, typeof -> the type of an object.
if you find "typeof" ugly, perhaps gettype looks better, as it resembles
getattr/item, etc.
>>> getattr(x, "y")
6
>>> gettype(6)
<type 'int'>
?
-tomer
On 5/22/06, Guido van Rossum <guido at python.org> wrote:
> I think this is a reasonable suggestion. Perhaps less code would break
> if you renamed the metaclass instead of the inquiry function.
>
> --Guido
>
More information about the Python-3000
mailing list