mutmut icon indicating copy to clipboard operation
mutmut copied to clipboard

Issue with `__init_subclass__` when not decorated as classmethod

Open gmuloc opened this issue 9 months ago • 1 comments

Hi, thanks for a great project!

I was stuck for a while on an issue where some attributes were not found properly from a mutated method (somehow object.__get_attribute__ was failing where getattr was succeeding, the context was on an ABCMeta object but I could not find anything related):

AttributeError: 'ABCMeta' object has no attribute 'xǁAntaTestǁ__init_subclass____mutmut_orig'. Did you mean: 'xǁAntaTestǁ__init_subclass____mutmut_1'?

It turns out, the issue was around the __init_subclass__ method that we have defined without a classmethod decorator. As per documentation: https://docs.python.org/3/reference/datamodel.html#customizing-class-creation the method is implicitly converted to classmethod if not declared as such.

As soon as I added the @classmethod decorator, I could move forward (to the next error but that's on me to solve).

From what I can see in the mutant file, __init_subclass__ is not mutated anymore so maybe not ideal.

Anyways, thought I would put this out there if it can help others ending up in the same situation. Feel free to close the issue.

gmuloc avatar Feb 27 '25 11:02 gmuloc

Thanks for the information. Yea, not super clear what to do in this case, but this information is a good start.

boxed avatar Feb 27 '25 15:02 boxed