I ran into an issue today with `str()` not behaving as I thought it should.
Given the following test script, what should happen?
-- 8< ------------------------------
class Blah(object):
def __str__(self):
return 'blah'
class Huh(int, Blah):
pass
class Hah(Blah, int):
pass
huh = Huh(7)
hah = Hah(13)
print(huh)
print(hah)
-- 8< ------------------------------
I thought I would get:
7
blah
and indeed, that is what I got for Pythons 2.7 - 3.7. However, starting with Python 3.8 I started getting:
blah
blah
To say the least, I was surprised.
Some searching turned up issue 36793: "Do not define unneeded __str__ equal to __repr__" .
As can be seen, `__str__` is needed for inheritance to work properly. Thoughts on reverting that patch?
--
~Ethan~
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/GLHE6CJ3IEHPUTA36YWOF5FSDLYNIOCV/
Code of Conduct: http://python.org/psf/codeofconduct/
Given the following test script, what should happen?
-- 8< ------------------------------
class Blah(object):
def __str__(self):
return 'blah'
class Huh(int, Blah):
pass
class Hah(Blah, int):
pass
huh = Huh(7)
hah = Hah(13)
print(huh)
print(hah)
-- 8< ------------------------------
I thought I would get:
7
blah
and indeed, that is what I got for Pythons 2.7 - 3.7. However, starting with Python 3.8 I started getting:
blah
blah
To say the least, I was surprised.
Some searching turned up issue 36793: "Do not define unneeded __str__ equal to __repr__" .
As can be seen, `__str__` is needed for inheritance to work properly. Thoughts on reverting that patch?
--
~Ethan~
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/GLHE6CJ3IEHPUTA36YWOF5FSDLYNIOCV/
Code of Conduct: http://python.org/psf/codeofconduct/