PEP-0318

Skip Montanaro skip at pobox.com
Tue Aug 10 12:17:14 EDT 2004


    >> Do people anticipate having lots of decorators for a given function?

    Mark> The way they've been talking, it would appear so. 

Most of the lots-of-decorator examples were probably designed to make a
competing decorator proposal look bad. ;-)

In reality, I think the number of functions acquiring decorators will be
fairly small unless you go whole hog for something like the
accepts()/returns() example in PEP 318 or do lots of Objective C interfacing
as Bob Ippolito expects to do.  In places where decorators will be used, I
suspect their number will typically be smaller than the number of parameters
to the decorated functions.  A quick scan of the standard library:

    find . -name '*.py' \
    | xargs cat \
    | egrep '^ *def .*\(.*\):$' \
    | sed -e 's/.*(//' -e 's/).*//' \
    | python -c 'import sys
    for l in sys.stdin:
      l = l.strip()
      if not l: print 0
      else: print len(l.split())
    ' | sort -n | uniq -c

suggests that most functions have three or fewer parameters:

    1096 0
    8072 1
    4024 2
    1696 3
     981 4
     278 5
      76 6
      57 7
       8 8
      10 9
       5 10
       1 11
       1 13

Even if you account for functions whose parameter lists span multiple lines
I doubt that distribution will change very much.

My guess is that use of decorators will be even more heavily weighted toward
0, even after a number of Python releases.

Skip



More information about the Python-list mailing list