Richard Oudkerk <shibt...@gmail.com> added the comment:

Shouldn't test___closure__() also test what happens when the closure is 
replaced with None, or a tuple which is too long or too short or contains 
non-cell objects?

All of these things seem to be checked when you create a new function using 
types.FunctionType:

>>> h = types.FunctionType(g.__code__, g.__globals__, "h", g.__defaults__, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: arg 5 (closure) must be tuple
>>> h = types.FunctionType(g.__code__, g.__globals__, "h", g.__defaults__, ())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: g requires closure of length 2, not 0
>>> h = types.FunctionType(g.__code__, g.__globals__, "h", g.__defaults__, 
>>> (1,2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: arg 5 (closure) expected cell, found int

I think the setter should make similar checks.  Maybe there is C code which 
assumes "broken" closures never happen.

----------
nosy: +sbt

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14369>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to