Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue12029] Catching virtual subclasses in except clauses

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

May 11, 2012, 4:31 AM

Post #1 of 17 (385 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses

Changes by Éric Araujo <merwok [at] netwok>:


----------
title: ABC registration of Exceptions -> Catching virtual subclasses in except clauses
versions: +Python 3.3 -Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 9:37 AM

Post #2 of 17 (379 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Guido van Rossum <guido [at] python> added the comment:

I agree it's a bug and should be fixed. It's too confusing that there would be two slightly different interpretations of isinstance/issubclass where the isinstance() and issubclass() would be using the extended interpretation but the except clause would use the narrow interpretation.

The exception matching done by the except clause ought to be explainable in terms of issubclass/isinstance.

----------
nosy: +gvanrossum

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 9:44 AM

Post #3 of 17 (378 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Changes by Éric Araujo <merwok [at] netwok>:


----------
stage: -> needs patch
versions: +Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 9:57 AM

Post #4 of 17 (377 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


----------
nosy: +benjamin.peterson
type: behavior -> enhancement
versions: -Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:04 AM

Post #5 of 17 (377 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Benjamin Peterson <benjamin [at] python> added the comment:

I think being able to catch exception with ABCs is esssentially useless. The originally stated "usecase" can be simply solved by putting classes into a tuple and putting that in the except clause.

In general, the whole abc machinary causes lots of code which expects instance and subclass checks to be side-effect free to be able to execute arbitrary code, which creates messes.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:09 AM

Post #6 of 17 (377 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

Perhaps ABCMeta could raise a UserWarning when creating an Exception subclass?

----------
nosy: +pitrou

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:20 AM

Post #7 of 17 (379 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

andrew cooke <andrew [at] acooke> added the comment:

perhaps it could just work in a simple, consistent way?

in my original report i wondered whether there was a significant performance hit. but so far the objections against fixing this seem to be (1) a lawyer could be convinced the current behaviour is consistent with the docs (2) python 3 should remain compatible with python 2 (3) abcmeta is the sucksorz.

those don't seem like great arguments against making it just work right, to me.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:22 AM

Post #8 of 17 (376 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Changes by andrew cooke <andrew [at] acooke>:


----------
nosy: -acooke

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:32 AM

Post #9 of 17 (376 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

> perhaps it could just work in a simple, consistent way?

That would be best obviously. But as Benjamin explained it's quite delicate to make it work while avoiding pitfalls where code involved in exception checking may itself fail with arbitrary errors - say, enter an infinite recursion. It's also why I think it would be a bad idea to fix it in 3.2 (the bugfix branch). In 3.3 we can take riskier decisions.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:37 AM

Post #10 of 17 (379 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Benjamin Peterson <benjamin [at] python> added the comment:

Basically, someone needs to produce a patch and we can go from there.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:47 AM

Post #11 of 17 (380 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

George-Cristian Bîrzan <gcbirzan [at] gmail> added the comment:

I posted on python dev that this would slow exception checking considerably so that is a concern. As for possible bugs, this has been working in the 2 branch for a while now, so I don't think that is the biggest issue.
As for possible use cases, writing a wrapper around backend, each with its own exceptions and still being able to catch a 'base' exception in your code while still having the ability to catch specific exceptions, without doing awkward stuff like looking at __cause__ (let alone that you have to reraise that in 2 for code that has to run on both branches). Yes, you could patch the exceptions' bases but that is what Abc was created to avoid.

Sorry for the mistakes and weird phrasing, posting this off my phone.

----------
nosy: +gcbirzan

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 10:49 AM

Post #12 of 17 (377 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

George-Cristian Bîrzan <gcbirzan [at] gmail> added the comment:

I have a patch, with tests, but no Internet on my computer so going out, will post it when I get back/my Internet comes back

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 1:17 PM

Post #13 of 17 (377 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Changes by Yury Selivanov <yselivanov [at] gmail>:


----------
nosy: +Yury.Selivanov

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 5:54 PM

Post #14 of 17 (361 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

James Henstridge <james [at] jamesh> added the comment:

Benjamin: if you are after a use case for this feature, see https://code.djangoproject.com/ticket/15901

In Django, there are multiple database backends, each of which currently catch the adapter's DatabaseError and reraise it as Django's DatabaseError so that Django code can handle database errors in a standard way without having to care about which backend they came from. Unfortunately, this loses some information from the exception.

My idea for solving that bug was to make Django's DatabaseError an ABC. By registering the various adapter's DatabaseErrors with the ABC, it would not be necessary to catch and reraise them in the backends while still preserving the ability to catch the generic errors in the core. This works fine in Python 2.x, but it was pointed out that it would cause compatibility problems when porting to Python 3.2.

----------
type: enhancement -> behavior

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 11, 2012, 6:09 PM

Post #15 of 17 (363 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Changes by James Henstridge <james [at] jamesh>:


----------
type: behavior -> enhancement

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 12, 2012, 3:48 AM

Post #16 of 17 (361 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

George-Cristian Bîrzan <gcbirzan [at] gmail> added the comment:

As promissed the patch. It doesn't break any tests, and it passes the ones I added. I have a pybench one as well, which even though trivial, does point to the fact that there is a degradation in performance, but not sure it's worth posting here.

----------
keywords: +patch
Added file: http://bugs.python.org/file25548/issue12029.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 23, 2012, 7:26 PM

Post #17 of 17 (350 views)
Permalink
[issue12029] Catching virtual subclasses in except clauses [In reply to]

Jim Jewett <jimjjewett [at] gmail> added the comment:

When does the performance hit occur?

If it is only when an exception has been raised, and its own class is not listed by the except clause, then I personally wouldn't worry about it; tracing the MRO *could* get arbitrarily long already; it just doesn't in practice. The same should be true of virtual subclassing.

On the other hand, if it adds another module or three to the required startup set, that might be a concern...

----------
nosy: +Jim.Jewett

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12029>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.