Bug report
Bug description:
Constructing a sentinel (new in 3.15 beta 1) from a str subclass works:
class MyStr(str):
def __str__(self) -> str:
return f'str {super().__str__()}'
def __repr__(self) -> str:
return f'repr {super().__repr__()}'
MISSING = sentinel(MyStr('MISSING'))
As per spec, the sentinel's name is the constructor's argument, i.e. MyStr:
print(type(MISSING.__name__), MISSING.__name__, repr(MISSING.__name__))
# <class '__main__.MyStr'> str MISSING repr 'MISSING'
However, the resulting sentinel's representation is confusing:
print(MISSING, [MISSING], {MISSING}, str(MISSING), repr(MISSING))
# MISSING [MISSING] {MISSING} str MISSING str MISSING
- straight output (
MISSING) gives the __name__'s super(): MISSING
- same for embedded (
[MISSING], {MISSING})
- but
str() and repr() return MyStr __name__, which then becomes 'str MISSING' in both cases
I don't know whether using a MyStr subclass is out of sentinel's scope (the PEP doesn't exclude AFAIK, but if so, then I suggest it should reject at construction), or that the output (different for MISSING and MISSING.__name__) can even be considered a bug. But it sure confused me!
CPython versions tested on:
3.15
Operating systems tested on:
Windows
Bug report
Bug description:
Constructing a
sentinel(new in 3.15 beta 1) from astrsubclass works:As per spec, the
sentinel's name is the constructor's argument, i.e.MyStr:However, the resulting
sentinel's representation is confusing:MISSING) gives the__name__'ssuper(): MISSING[MISSING],{MISSING})str()andrepr()returnMyStr__name__, which then becomes 'str MISSING' in both casesI don't know whether using a
MyStrsubclass is out ofsentinel's scope (the PEP doesn't exclude AFAIK, but if so, then I suggest it should reject at construction), or that the output (different forMISSINGandMISSING.__name__) can even be considered a bug. But it sure confused me!CPython versions tested on:
3.15
Operating systems tested on:
Windows