Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

#1143 added type as a reserved field name because type is used in type annotations, which renames OpenAPI fields with the name type to type_.

RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - {

This leads to extra confusion for users of the client because this common field name no longer matches the API spec.

The rationale given in #1143 (comment) was that this is due to local variable names, but Python supports shadowing (for built ins as well, such as type), to support this very reason. For example this code runs fine on Python 3.9+:

def f(a: type[int | str]) -> None:
    type = 1
    print(f"{type}: {a}")

f(int)

Output: 1: <class 'int'>

At a higher level, the Python core team makes a big effort to avoid these kinds of breaking changes that affect variable naming. For example, when pattern matching was added, match was added a soft keyword so that anyone using match as a local variable name would not be affected.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.