This is a static archive of the Python wiki, which was retired in February 2026 due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

-- DavidLambert 2007-07-18 14:49:27

Nameless functions, nameless types.

Please, what is purpose of name argument to new type call?

'''
$ python
Python 2.5.1 (r251:54863, Jun 25 2007, 14:55:49) 
[GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
'''

cls1 = type('*',(object,),{})        # create type named by asterisk.
# del *                              # silly.
# del '*'                            # silly.


cls2 = type('*',(object,),{'f':lambda s,x: x*3})
# cls1().f('abc')                    # causes expected AttributeError
cls2().f('abc') == 'abcabcabc'       # class name unused


str(cls1) == "<class '__main__.*'>"
str(cls2) == "<class '__main__.*'>"  # so what, the classes differ.


cls_named = type('valid_name',(object,),{})
# del valid_name                     # raises NameError


class C(object):
    pass
del C

2026-02-14 16:12