Skip to content

Codec.encode/decode should be documented as positional only #109444

@srittau

Description

@srittau

Documentation

The codecs docs specify the encode/decode functions to be positional or kwargs:

Codec.encode(input, errors='strict')
Codec.decode(input, errors='strict')

This contradicts at least some built-in codecs:

Python 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs
>>> enc = codecs.getencoder("utf8")
>>> enc(input="abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: _codecs.utf_8_encode() takes no keyword arguments

For consistency's sake I suggest to also annotate the incremental en-/decoders to specify positional-only arguments, although they are positional or kwargs at runtime.

Cf. python/typeshed#10657 and python/typeshed#10713.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions