Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Add Optional in Decorator factories #14156

Merged
merged 1 commit into from
Nov 21, 2022
Merged

Conversation

tomschr
Copy link
Contributor

@tomschr tomschr commented Nov 21, 2022

Situation

The documentation shows an example in the "Decorator factories" section and it looks like this:

# Implementation
def atomic(__func: Callable[..., Any] = None, *, savepoint: bool = True):
    # pruned

However, if you save the file and run mypy, it complains about the previous line:

error: Incompatible default for argument "__func" (default has type "None", argument has type "Callable[..., Any]")  [assignment]
note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True

Proposed change

This change adds Optional around Callable[..., Any]] which avoids the above error message.

mypy complains about

  error: Incompatible default for argument "__func" (default has type "None", argument has type "Callable[..., Any]")  [assignment]
  note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True

This change adds Optional around "Callable[..., Any]] = None"
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the fix!

@hauntsaninja hauntsaninja merged commit c660354 into python:master Nov 21, 2022
@tomschr tomschr deleted the patch-1 branch November 21, 2022 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants