On 12/12/05, Adam Olsen <[EMAIL PROTECTED]> wrote: > When I need an identifier unique to a class I just use a reference to > the class itself. As such I'd like to suggest that > obj.__private > be converted to > obj.__dict__[(type(obj), '__private')] > > Note that I'm accessing __dict__ directly so as to avoid getattr's > requirement for attribute names to be strings. > > Obviously it doesn't handle backwards compatibility, so it's more of a > "if I could do it again.." suggestion.
but that's not the same at all. The point of __private is that it uses the *static* scope of the code that contains the reference, not the (dynamic) type of the object being referenced. With your approach, if class A defined __private, *anyone* could use A().__private (but not B().__private where B is a subclass of A). The intention is for __private to have the right meaning only within the source code for class A, but it should work even if type(self) is a subclass of A. (Or even if it's unrelated to A, but that's a separate and weaker use case.) -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com