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

Friendlier errors for PEP 612 #12832

Merged
merged 3 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions mypy/typeanal.py
Expand Up @@ -944,9 +944,9 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
)
if maybe_ret is None:
# Callable[?, RET] (where ? is something invalid)
# TODO(PEP612): change error to mention paramspec, once we actually have some
Copy link
Member

Choose a reason for hiding this comment

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

Or Concatenate?

Copy link
Member

Choose a reason for hiding this comment

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

Though that's getting a bit much for an error message.

Copy link
Collaborator

@ethanhs ethanhs May 21, 2022

Choose a reason for hiding this comment

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

I like the new language, maybe a note linking to some docs would be useful in addition however.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, Concatenate is why I went with the more generic "parameter specification" rather than "ParamSpec". This error is probably disproportionately encountered by new users, so don't want it to be too scary.

I could add a note for https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas

# support for it
self.fail('The first argument to Callable must be a list of types or "..."', t)
self.fail(
'The first argument to Callable must be a '
'list of types, parameter specification, or "..."', t)
return AnyType(TypeOfAny.from_error)
ret = maybe_ret
else:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/semanal-errors.test
Expand Up @@ -867,7 +867,7 @@ x = None # type: Callable[int, str]
y = None # type: Callable[int]
z = None # type: Callable[int, int, int]
[out]
main:2: error: The first argument to Callable must be a list of types or "..."
main:2: error: The first argument to Callable must be a list of types, parameter specification, or "..."
main:3: error: Please use "Callable[[<parameters>], <return type>]" or "Callable"
main:4: error: Please use "Callable[[<parameters>], <return type>]" or "Callable"

Expand Down