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.

classification
Title: There is a problem with the setdefault type conversion in the tuple
Type: Stage: resolved
Components: Windows Versions: Python 3.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, sk xing, steve.dower, steven.daprano, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2017-09-19 03:11 by sk xing, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
demo.py sk xing, 2017-09-19 03:11
Messages (2)
msg302497 - (view) Author: sk xing (sk xing) Date: 2017-09-19 03:11
The setdefault method of the tuple allows the introduction of custom data types.At this point, the __repr__ method is implemented so that the returned data type has an error.The type of str is returned, but the int type is written to the tuple.Also, write str without quotation marks.
Look at the demo.py in the attachment
msg302504 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2017-09-19 06:05
The demo code you give seems to be working perfectly correctly. I don't think anything here is a bug.

(1) You are working with a dict, not a tuple.

(2) The potint.__repr__ method does NOT have a bug.

(3) de['four'] is NOT an int, it is a potint object, just as you set. It only looks like an int when you print it because that's what the __repr__ does.

To see what the object really is, call:

type(de['four'])

and you will see it is a potint.


And I have no idea what you think is wrong with string without quotation marks, it works correctly in the demo.


I'm going to close this bug report as Works For Me. If you disagree, please re-open it with more information.
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75695
2017-09-19 06:05:32steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg302504

resolution: works for me
stage: resolved
2017-09-19 03:11:33sk xingcreate