79647138

Date: 2025-06-01 03:02:25
Score: 1
Natty:
Report link

Wow, that was fast. Thanks to @STerliakov for finding a related post!

The solution is generics. So the BusinessMan declaration becomes

class BusinessMan[BriefcaseType: Briefcase]:
    # snip

    @classmethod
    def from_briefcase(cls, briefcase: BriefcaseType) -> Self:
        # snip

which indicates that from_briefcase() takes a BriefcaseType, which is any subclass of Briefcase.

The declaration for BiggerBusinessMan becomes

class BiggerBusinessMan(BusinessMan[BiggerBriefcase]):
    # snip

    @classmethod
    def from_briefcase(cls, briefcase: BiggerBriefcase) -> Self:
        # snip

which says that BiggerBusinessMan inherits from the variant of BusinessMan where BriefcaseType is BiggerBriefcase.

Type annotations are sublime.

Pleasure doing business!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Whitelisted phrase (-1): solution is
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @STerliakov
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Quantasm