Skip to content

Fix runtime not generic note for type aliases, update for PathLike #9512

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

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 12 additions & 7 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,25 +970,28 @@ def tuple_type(self, items: List[Type]) -> TupleType:


def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,
typ: Type, fullname: Optional[str] = None,
orig_type: Type, fullname: Optional[str] = None,
unexpanded_type: Optional[Type] = None) -> AnyType:
if disallow_any:
if fullname in nongen_builtins:
typ = orig_type
# We use a dedicated error message for builtin generics (as the most common case).
alternative = nongen_builtins[fullname]
fail(message_registry.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), typ,
code=codes.TYPE_ARG)
else:
typ = unexpanded_type or typ
typ = unexpanded_type or orig_type
type_str = typ.name if isinstance(typ, UnboundType) else format_type_bare(typ)

fail(
message_registry.BARE_GENERIC.format(
quote_type_string(type_str)),
message_registry.BARE_GENERIC.format(quote_type_string(type_str)),
typ,
code=codes.TYPE_ARG)

if fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES:
base_type = get_proper_type(orig_type)
base_fullname = (
base_type.type.fullname if isinstance(base_type, Instance) else fullname
)
if base_fullname in GENERIC_STUB_NOT_AT_RUNTIME_TYPES:
# Recommend `from __future__ import annotations` or to put type in quotes
# (string literal escaping) for classes not generic at runtime
note(
Expand All @@ -1000,7 +1003,9 @@ def get_omitted_any(disallow_any: bool, fail: MsgCallback, note: MsgCallback,

any_type = AnyType(TypeOfAny.from_error, line=typ.line, column=typ.column)
else:
any_type = AnyType(TypeOfAny.from_omitted_generics, line=typ.line, column=typ.column)
any_type = AnyType(
TypeOfAny.from_omitted_generics, line=orig_type.line, column=orig_type.column
)
return any_type


Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ from queue import Queue
p: PathLike
q: Queue
[out]
test.py:4: error: Missing type parameters for generic type "_PathLike"
test.py:4: error: Missing type parameters for generic type "PathLike"
test.py:4: note: Subscripting classes that are not generic at runtime may require escaping, see https://mypy.readthedocs.io/en/latest/common_issues.html#not-generic-runtime
test.py:5: error: Missing type parameters for generic type "Queue"
test.py:5: note: Subscripting classes that are not generic at runtime may require escaping, see https://mypy.readthedocs.io/en/latest/common_issues.html#not-generic-runtime
Expand Down