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

Fix misleading error message: Mypy shoould not suggest Foo[...] if annotation contains Foo(arg=...) etc. #16643

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
removed any misleading notes by accounting for when self.parent is No…
…ne in the function visitCall in mypy/fastparse.py
  • Loading branch information
mingminggl committed Dec 8, 2023
commit cf24ea630cd4f9a5c75ff7e65649043e580e159c
2 changes: 2 additions & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,8 @@ def visit_Call(self, e: Call) -> Type:
f = e.func
constructor = stringify_name(f)

if self.parent() is None:
return self.invalid_type(e, note="")
if not isinstance(self.parent(), ast3.List):
note = None
if constructor:
Expand Down
12 changes: 12 additions & 0 deletions mypy/test/testming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import annotations
from typing import Annotated

class _EnvironmentVariables():
def __init__(self, variables: dict[str, bytes]) -> None:
self.__variables = variables

def EnvironmentVariables(sort: bool): # noqa (This func is imitating a type name, so upper-camel-case is ok)
return Annotated[_EnvironmentVariables, dict]

def unsorted_env_variables(variables: EnvironmentVariables(sort=False)) -> None:
return variables.as_json_obj()