Author josh.r
Recipients BNMetrics, gvanrossum, josh.r, pablogsal, pekka.klarck, xtreak
Date 2018-11-07.21:27:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541626067.26.0.788709270274.issue34805@psf.upfronthosting.co.za>
In-reply-to
Content
I'm also a little skeptical of the OP's proposed use case for other reasons. In any circumstance other than "all classes are defined in the same module", you can't really make useful guarantees about subclass definition order, because:

1. If the converters are defined in multiple modules in a single package, the module with IntConverter could be imported first explicitly, and now BoolConverter will come second.

2. If all the provided converters occur in a single monolithic module, and some other package tries to make a converter for their own int subclass, well, IntConverter is already first in the list of subclasses, so the other package's converter will never be called (unless it's for the direct subclass of int, rather than a grandchild of int, but that's an implementation detail of the OP's project).

Essentially, to write such a class hierarchy properly, you'd need to rejigger the ordering each time a class was registered such that any converter for a parent class was pushed until after the converter for all of its descendant classes (and if there is multiple inheritance involved, you're doomed).

Even ignoring all that, their use case doesn't require explicit registration if they don't want it to. By making a simple metaclass for the root class, the metaclass's __new__ can perform registration on the descendant class's behalf, either with the definition time ordering of the current design, or with a more complicated rejiggering I described that would be necessary to ensure parent classes are considered after child classes (assuming no multiple inheritance).
History
Date User Action Args
2018-11-07 21:27:47josh.rsetrecipients: + josh.r, gvanrossum, pekka.klarck, pablogsal, xtreak, BNMetrics
2018-11-07 21:27:47josh.rsetmessageid: <1541626067.26.0.788709270274.issue34805@psf.upfronthosting.co.za>
2018-11-07 21:27:47josh.rlinkissue34805 messages
2018-11-07 21:27:47josh.rcreate