A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2008-October/082980.html below:

[Python-Dev] __getattr__ and new style classes

[Python-Dev] __getattr__ and new style classesAmaury Forgeot d'Arc amauryfa at gmail.com
Fri Oct 10 02:28:49 CEST 2008
Hello,

On Fri, Oct 10, 2008 at 2:15 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>
>> If the time is being spent in PyErr_Format, how far could you get adding
>> a dedicated function for creating AttributeErrors? Something along the
>> lines of:
>>
>> PyErr_AttributeError(PyObject *object, PyObject *attr_name)
>
> More generally, it might be useful to have some mechanism for
> deferred instantiation of exceptions, so you can do something
> like indicate what type of exception you want to raise, and
> specify a function and some arguments to call to instantiate
> the exception, but the instantiation itself doesn't happen
> unless the exception object is actually needed by Python
> code.

But this is already the case, and the reason why there are three
variable to describe an exception: type, value and traceback.
At the C level, the value is often a string (when using PyErr_Format,
for example), or a tuple.
Normalization (=creation of the exception object) only occurs when
needed, e.g when entering an "except:" handler in python code, or when
the exception is printed.
However, the "value" string object must be created anyway, and this
could be avoided in most Getattr cases.

-- 
Amaury Forgeot d'Arc
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4