How much is set in stone?
Barry A. Warsaw
barry at zope.com
Tue Nov 6 01:04:26 EST 2001
>>>>> "BP" == Bjorn Pettersen <BPettersen at NAREX.com> writes:
BP> Note that this happens *only* when your misspelling is on the
BP> lhs of an assignment statement, in *all* other contexts the
BP> compiler will complain at you. I've written several large
BP> Python projects and I've never run into this problem --
BP> i.e. it's not high on my priority list. If it's important to
BP> you I would suggest you run PyChecker
BP> (http://pychecker.sourceforge.net/) on the code...
One possible way to accomplish this is new with Python 2.2. With
new-style classes, you could use a __slots__ attribute to cause any
assignments to misspelled attributes to generate an error. Not
exactly local variable assertions, but maybe close enough where it
matters:
Python 2.2b1+ (#1, Nov 1 2001, 02:06:16)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class NotSoStrict:
... pass
...
>>> n = NotSoStrict()
>>> n.python = 1
>>> n.phyton = 2
>>>
>>> class Strict(object):
... __slots__ = ('python',)
...
>>> s = Strict()
>>> s.python = 1
>>> s.phyton = 2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'Strict' object has no attribute 'phyton'
guido-left-the-keys-to-his-time-machine-laying-on-his-desk-again-ly y'rs,
-Barry
More information about the Python-list
mailing list