Skip to content

Commit cc7fb08

Browse files
committed
Check for future import
1 parent 1ca6a85 commit cc7fb08

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

pylint/extensions/typing.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pylint.checkers.utils import (
88
check_messages,
99
is_node_in_type_annotation_context,
10+
is_postponed_evaluation_enabled,
1011
safe_infer,
1112
)
1213
from pylint.interfaces import INFERENCE, IAstroidChecker
@@ -307,6 +308,11 @@ def _check_broken_noreturn(self, node: Union[nodes.Name, nodes.Attribute]) -> No
307308
# NoReturn not part of a Union or Callable type
308309
return
309310

311+
if is_postponed_evaluation_enabled(node) and is_node_in_type_annotation_context(
312+
node
313+
):
314+
return
315+
310316
for inferred in node.infer():
311317
# To deal with typing_extensions, don't use safe_infer
312318
if (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
'typing.NoReturn' is broken inside compond types for Python 3.7.0
3+
https://bugs.python.org/issue34921
4+
5+
If no runtime introspection is required, use string annotations instead.
6+
7+
With 'from __future__ import annotations', only emit errors for nodes
8+
not in a type annotation context.
9+
"""
10+
# pylint: disable=missing-docstring
11+
from __future__ import annotations
12+
13+
import typing
14+
from typing import Callable, NoReturn, Union
15+
16+
import typing_extensions
17+
18+
19+
def func1() -> NoReturn:
20+
raise Exception
21+
22+
def func2() -> Union[None, NoReturn]:
23+
pass
24+
25+
def func3() -> Union[None, "NoReturn"]:
26+
pass
27+
28+
def func4() -> Union[None, typing.NoReturn]:
29+
pass
30+
31+
def func5() -> Union[None, typing_extensions.NoReturn]:
32+
pass
33+
34+
35+
Alias1 = NoReturn
36+
Alias2 = Callable[..., NoReturn] # [broken-noreturn]
37+
Alias3 = Callable[..., "NoReturn"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[master]
2+
py-version=3.7
3+
load-plugins=pylint.extensions.typing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
broken-noreturn:33:23:33:31::'NoReturn' inside compound types is broken in 3.7.0 / 3.7.1:INFERENCE

0 commit comments

Comments
 (0)