[Python-ideas] Mitigating 'self.' Method Pollution

Chris Angelico rosuav at gmail.com
Sat Jul 11 10:38:34 CEST 2015

On Sat, Jul 11, 2015 at 6:33 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
>> And, for folks who still prefer to prefix all their field references
>> with 'self.', the proposal in no way prevents them from doing so. It
>> merely allows the rest of us to be a bit less wordy and more pithy in
>> our code.
> Python requires explicit declaration of the namespace for names. That
> protects me from ambiguities that would otherwise be very common in
> other people's code. I appreciate that and do not want it threatened.

Not quite true; Python requires explicit declaration of names when
they're bound to, but is quite happy to do a scope search (local,
nonlocal, global, builtin) for references. But the rules are fairly
simple. Aside from the possibility that someone imports your module
and sets module.len to shadow a builtin, everything can be worked out
lexically by looking for the assignments.


More information about the Python-ideas mailing list