Message406222
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') |
|
Date |
User |
Action |
Args |
2021-11-12 17:10:57 | rhettinger | set | recipients:
+ rhettinger, gvanrossum, serhiy.storchaka |
2021-11-12 17:10:57 | rhettinger | set | messageid: <1636737057.14.0.650922986771.issue45791@roundup.psfhosted.org> |
2021-11-12 17:10:57 | rhettinger | link | issue45791 messages |
2021-11-12 17:10:57 | rhettinger | create | |
|