Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

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')

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45791>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to