[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread miss-islington


miss-islington  added the comment:


New changeset c0063bdc7b5fed98c6799f3da0a954a775e3d89e by Miss Islington (bot) 
in branch '3.9':
bpo-47007: [doc] `str` special method lookup (GH-31863)
https://github.com/python/cpython/commit/c0063bdc7b5fed98c6799f3da0a954a775e3d89e


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread miss-islington


miss-islington  added the comment:


New changeset f502dadb332f911fa3b6c531bbc5065795cca242 by Miss Islington (bot) 
in branch '3.10':
bpo-47007: [doc] `str` special method lookup (GH-31863)
https://github.com/python/cpython/commit/f502dadb332f911fa3b6c531bbc5065795cca242


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

Thanks for the report and fix!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread miss-islington


Change by miss-islington :


--
pull_requests: +30380
pull_request: https://github.com/python/cpython/pull/32319

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:


New changeset bb86d1d9fbd1888524e04475383f4ea764277f67 by Vanshaj Singhania in 
branch 'main':
bpo-47007: [doc] `str` special method lookup (GH-31863)
https://github.com/python/cpython/commit/bb86d1d9fbd1888524e04475383f4ea764277f67


--
nosy: +JelleZijlstra

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-04-04 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 4.0 -> 5.0
pull_requests: +30379
pull_request: https://github.com/python/cpython/pull/32318

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-03-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

You mean `type(object).__str__(object)` instead of `type(object).__str__()`, 
obviously.

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-03-13 Thread Vanshaj Singhania


Change by Vanshaj Singhania :


--
keywords: +patch
pull_requests: +29961
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31863

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-03-13 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47007] [doc] str docs are inconsistent with special method lookup

2022-03-13 Thread Vanshaj Singhania

New submission from Vanshaj Singhania :

The documentation for the `str` class[^1] says:

> If neither encoding nor errors is given, str(object) returns object.__str__()

This led our students[^2] to try the following code:

>>> class Test:
... def __str__(self):
... return 'hi'
... 
>>> test = Test()
>>> test.__str__ = lambda self: 'bye'
>>> str(test)

The expected result was calling `test.__str__()`, but instead the interpreter 
output was `'hi'`.

The docs for special method lookup[^3] do say that instance attributes are 
ignored:

> For custom classes, implicit invocations of special methods are only 
> guaranteed to work correctly if defined on an object’s type, not in the 
> object’s instance dictionary.

This makes sense, and explains the observed behavior, but the `str` class docs 
seem to be inconsistent with this. Perhaps it would be more clear if the `str` 
documentation mentioned that it called `type(object).__str__()` instead of 
`object.__str__()`.

[^1]: https://docs.python.org/3/library/stdtypes.html#str
[^2]: CS 61A at UC Berkeley, https://cs61a.org
[^3]: https://docs.python.org/3/reference/datamodel.html#special-method-lookup

--
assignee: docs@python
components: Documentation
messages: 415110
nosy: docs@python, itsvs
priority: normal
severity: normal
status: open
title: [doc] str docs are inconsistent with special method lookup
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com