bpo-31222: Make (datetime|date|time).replace return subclass type in Pure Python by pganssle · Pull Request #4176 · python/cpython (original) (raw)
I don't have particularly strong opinions on the naming here, I mainly used C
because test_subclass_date
and test_subclass_time
both use C
as their "in-function subclass", and there are already top-level SubclassTime
/SubclassDate
/SubclassDatetime
classes that are used to run all or nearly all the tests again on a subclass (presumably to check that subclasses satisfy the same contract as the base class). I think DateSubclass
might get confused with these other test classes.
Another alternative which avoids this question entirely is to replace the specific test_subclass_replace
function with a test_replace_class
function (which will automatically get the subclass check by virtue of the inheritance through TestSubclassDateTime
). The main reasons I didn't do this are that 1. I think the logic is a bit clearer (why are you checking that .replace
returns the same class as the object?) and 2. this way it automatically "recurses" the check such that it's clear that even subclasses retain this property. This is a fairly weakly-held opinion, though, and I'm willing to be changed.
If we do decide that renaming is best, would maybe _Subclass
be a reasonable name?