This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients gvanrossum, rhettinger, serhiy.storchaka
Date 2021-11-12.17:10:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
FWIW, I discovered the issue when experimenting with ways to use the class pattern in structural pattern matching.

--- Code that should work but doesn't -----------

class Warm:
    def __instancecheck__(cls, inst):
        return inst in {'red', 'orange', 'blue'}
match 'red':
    case Warm():              # This doesn't match but should

--- What you have to do to get it to work -------

class MetaWarm(type):
    def __instancecheck__(cls, inst):
        return inst in {'red', 'orange', 'blue'}

class Warm(metaclass=MetaWarm):

match 'red':
    case Warm():          # This matches
Date User Action Args
2021-11-12 17:10:57rhettingersetrecipients: + rhettinger, gvanrossum, serhiy.storchaka
2021-11-12 17:10:57rhettingersetmessageid: <>
2021-11-12 17:10:57rhettingerlinkissue45791 messages
2021-11-12 17:10:57rhettingercreate