Skip to content

Unify method signature format in str #96354

@ofey404

Description

@ofey404

Documentation

Currently, there are two different method signature style in builtin type str.

  • The new style, marking the positional only parameters, like zfill(self, width, /)
  • The old style, leading with S., and should use an extra line to describe the signature.
    • Currently there are 9 S. started methods: count, endswith, find, format, format_map, index, rfind, rindex and startswith.

Example of new style and old style:

## New Style:

help(str.zfill)
# Help on method_descriptor:
# 
# zfill(self, width, /)
#     Pad a numeric string with zeros on the left, to fill a field of the given width.
#     
#     The string is never truncated.


## Old Style:

help(str.find)
# Help on method_descriptor:
# 
# find(...)
#     S.find(self, sub, start=None, end=None, /) -> 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.

Suggestion

Change the 9 old style documentation to the new style:

  • count, endswith, find, format, format_map, index, rfind, rindex and startswith.

Take str.find as an example, it would be more concise and consistent:

help(str.find)
# Help on method_descriptor:
# 
# find(self, sub, start=None, end=None, /) -> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions