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 <1636737057.14.0.650922986771.issue45791@roundup.psfhosted.org>
In-reply-to
Content
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
        print('Glowing')


--- 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):
    pass

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