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: The string find method shows the problem
Type: Stage:
Components: Documentation Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: andy.ye.jx, andyye, docs@python, eric.smith, steven.daprano
Priority: normal Keywords:

Created on 2020-12-29 03:19 by andyye, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
截屏2020-12-29 上午10.57.53.png andyye, 2020-12-29 03:19
Messages (4)
msg383949 - (view) Author: andy ye (andyye) Date: 2020-12-29 03:19
data = 'abcddd'
# True
data.find('a', 0)

# False
data.find('a', start=0)


# document
class str(obj):

    def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.find(sub[, start[, end]]) -> int
        
        Return the lowest index in S where substring sub is found,
        such that sub is contained within S[start:end].  Optional
        arguments start and end are interpreted as in slice notation.
        
        Return -1 on failure.
        """
        return 0
msg383951 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-12-29 03:35
# True
data.find('a', 0)

That will return 0, not True.


# False
data.find('a', start=0)


And that will raise TypeError, not return False.


What exactly are you reporting here? I have read your bug report, and looked at the screen shot, and I have no idea what problem you think you have found or what you want to change about the documentation.
msg383961 - (view) Author: ye andy (andy.ye.jx) Date: 2020-12-29 06:09
When I say True here, I'm not talking about querying, I'm talking about
syntax, as far as I know, document is supposed to support keyword
arguments, but it doesn't

Steven D'Aprano <report@bugs.python.org> 于2020年12月29日周二 上午11:36写道:

>
> Steven D'Aprano <steve+python@pearwood.info> added the comment:
>
> # True
> data.find('a', 0)
>
> That will return 0, not True.
>
>
> # False
> data.find('a', start=0)
>
>
> And that will raise TypeError, not return False.
>
>
> What exactly are you reporting here? I have read your bug report, and
> looked at the screen shot, and I have no idea what problem you think you
> have found or what you want to change about the documentation.
>
> ----------
> nosy: +steven.daprano
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue42776>
> _______________________________________
>
msg383981 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-12-29 11:45
'abcddd'.find('a', start=0) would appear to be allowed from the help text, but it isn't legal. This is because .find() does not allow keyword arguments.

It looks like find could be documented as
find(self, sub, start=None, end=None, /)

Although it doesn't look like any of the str methods use self in the documentation.

I'm reasonably sure None is correct as the default for start and end, but I suspect it's not universally true of str methods that None works as the default. So it wouldn't surprise me if not all of the str methods  can be expressed in python code.
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86942
2020-12-29 11:45:33eric.smithsetnosy: + eric.smith
messages: + msg383981
2020-12-29 06:09:04andy.ye.jxsetnosy: + andy.ye.jx
messages: + msg383961
2020-12-29 03:35:58steven.dapranosetnosy: + steven.daprano
messages: + msg383951
2020-12-29 03:19:59andyyecreate