Case Statements
Steven D'Aprano
steve at pearwood.info
Wed Mar 16 21:54:22 EDT 2016
On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote:
> Yes... in theory. But try rewriting my example to avoid decorator
> syntax. It won't work, because of this line:
>
> orig = globals()[cls.__name__]
That's a nasty, dirty piece of code, and I hope you are thoroughly ashamed
of having written it :-)
> It depends on the decorator being run before the name actually gets
> bound - which means the previous class is available to the decorator.
> You can't do that without decorator syntax, or messing around with
> multiple names.
I wouldn't want to rely on it working with decorator syntax either. Even if
it does now, I'm not sure that's a language guarantee.
--
Steven
More information about the Python-list
mailing list