Benjamin Peterson wrote:
2009/5/8 Terry Reedy <tjre...@udel.edu>:
2. I am puzzled why those two methods should be extra special, but don't
know enough to say more.

They're not supposed to be special, which is the reason for this
message. :) Currently the interpreter will call __getattr__ when
looking them up. This is not the way it should be.

I was trying to ask the same question as Daniel did more clearly, and which you answered: they are special special methods because they are not in the PyTypeObject struct like the other special (name) methods. And that, I presume, is because they are specific to context manager objects, while all other 'special' methods (that I notice in 'Special method names') are more general in being applicable to multiple types.

Since built-in functions are compiled to load_global, call_function and operations to various special op codes, I could imagine that .__enter__ and .__exit__ are currently the only implicitly invoked special names that explicitly appear in code objects. I can see why you ask before burning an opcode (with parameter) to avoid that.

There are two issues: 1) bypass instance lookup; 2) bypass .__getattribute__() calling. I presume you have or can do at least the first with a custom .__getattribute__ method.

Terry Jan Reedy





_______________________________________________
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

Reply via email to