What is dict?

Steve Holden sholden at holdenweb.com
Tue Aug 13 00:21:35 CEST 2002


"Gregory (Grisha) Trubetskoy" <grisha at ispol.com> wrote in message
news:Pine.BSF.4.32.0208121753590.27709-100000 at localhost...
>
> In the Library Reference, dict is described as a built-in function which
> returns a dictionary object. type(dict) reports it as <type 'type'>, which
> it is, of course, being a short-hand for types.DictType or
> types.DictionaryType.
>
Not quite:>>> from types import TypeType
>>> type(dict) == TypeType
1
>>>

dict() is a type, so its type is types.TypeType -- even types must have a
type!

> My question is concerned with the documentation: I wrote a type (in C)
> that is a totally "new" (as opposed to "classic")  object and can be
> subclassed, and documenting it as a built-in function like dict() just
> doesn't feel right.
>
I wonder. Types are callables, and really they act as factory functions.
Some of them can take a variety of parameters -- for example, you can call
dict() with a mapping object (including an existing dictionary) or a
sequence of pairs (each of which will be treated as a key-value pair).

> What is consensus within the Python community? Is calling dict a function
> a case of a misnomer?
>
I think that all the types should be clearly identified as such, but they
are built in and callable, so what's the harm in describing them (for the
benefit of newcomers) as functions? What's in a name?

if-it-quacks-like-a-function-ly y'rs  - steve
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list