Message150346
Interesting thought, the syntax seems unnecessary. Adding new syntax to the language is something that happens rarely and only with a _lot_ of consideration.
As a slightly more verbose alternative, currently you can do this:
def fail_if_defined(*args, namespace):
for name in args:
if name in namespace:
raise AlreadyBoundError(name)
And in your code you would put the following where you cared about it:
fail_if_defined("FILE", "header", namespace=locals())
You could even drop the namespace parameter (since it's sort of boilerplate):
def fail_if_defined(*args):
namespace = inspect.currentframe().f_back.f_locals
for name in args:
if name in namespace:
raise AlreadyBoundError(name)
However, if you are going to the trouble of sticking those in place (or of selectively using a new syntax), you are likely paying attention to the the situation already, rendering either solution unnecessary.
Ultimately, this is something better addressed instead by keeping your functions small, by being a little more cautious in naming, and particularly by careful unit testing. |
|
Date |
User |
Action |
Args |
2011-12-29 20:09:55 | eric.snow | set | recipients:
+ eric.snow, Jimbofbx |
2011-12-29 20:09:55 | eric.snow | set | messageid: <1325189395.71.0.541970672833.issue13678@psf.upfronthosting.co.za> |
2011-12-29 20:09:55 | eric.snow | link | issue13678 messages |
2011-12-29 20:09:54 | eric.snow | create | |
|