[Python-Dev] PEP 318 - generality of list; restrictions on elements

Jewett, Jim J jim.jewett at eds.com
Mon Mar 8 14:21:34 EST 2004

Given that some syntax will be chosen, what are the
restrictions on the wrappers?

Right now, the variable portion of the syntax is:

	'[' wrapper (, wrapper)* ']'

What else should be accepted, to avoid surprises?

	Variables that evaluate to a list?
	Expressions that evaluate to a list?
	List comprehensions?
	Single wrappers?

What are the restrictions on list items?

	Only a function?
	Only a code object?  (I assume so)
	Must the code return the original function?
	Must the code return a code object?  

In other words, which of the following examples
should work, which should fail, and which should
depend on whatever is easiest?

1.	# fail, integer not a callable?  (Don't try to slice the args!)
	def name(args)[0]:

2.	# fail, as w[0] is itself a (non-callable) list?
	w = [wrapper]
	def name(args) [w]:

3.	# fail, not a list?
	def name(args) classmethod:

4.	# ??? lambda would be OK, except for the second ":"
	def name(args)[lambda x: x]:

5.	# should succeed?
	def name(args)[x for x in decorators if x in active]:	

6.	# ??? wrapper does not return a callable.
	y = lambda x: None
	def name(args) [y]:

7.	# a list, but no '[]'.  either surprises.
	def name(args) list((wrap1, wrap2)):

8.	# a list, but no '[]'.  either surprises.
	w = [wrapper]
	def name(args) w:		

9.	# a list, but no '[]'.  either surprises.
	def w(): return [y,y,y]
	def name(args) w():

Do the wrappers have to be defined when the definition starts?
Just defined before the module finishes its definition?
Before the definition is executed?  In other words, are these OK?

def outer():
    # w not defined at module load, but defined before any call
    def inner(x)[w]:
        print x
    return inner

But if that is OK, then which w would be used in the next example?
w is redefined "later", but before inner is actually called.

def w(fn): 
    print "outside w"
    return fn

def outer():
    # w not defined yet, but defined in this
    def inner(x)[w]:
        print x
    def w(fn):
        return fn

How about this?  There is no guarantee that othermod
will finish loading first, though I suppose that 
already causes problems today.

import othermod
def fn()[othermod.wrap]:


More information about the Python-Dev mailing list