Skip to content

Commit

Permalink
Check for future import
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Mar 10, 2022
1 parent 1ca6a85 commit cc7fb08
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pylint/extensions/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pylint.checkers.utils import (
check_messages,
is_node_in_type_annotation_context,
is_postponed_evaluation_enabled,
safe_infer,
)
from pylint.interfaces import INFERENCE, IAstroidChecker
Expand Down Expand Up @@ -307,6 +308,11 @@ def _check_broken_noreturn(self, node: Union[nodes.Name, nodes.Attribute]) -> No
# NoReturn not part of a Union or Callable type
return

if is_postponed_evaluation_enabled(node) and is_node_in_type_annotation_context(
node
):
return

for inferred in node.infer():
# To deal with typing_extensions, don't use safe_infer
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
'typing.NoReturn' is broken inside compond types for Python 3.7.0
https://bugs.python.org/issue34921
If no runtime introspection is required, use string annotations instead.
With 'from __future__ import annotations', only emit errors for nodes
not in a type annotation context.
"""
# pylint: disable=missing-docstring
from __future__ import annotations

import typing
from typing import Callable, NoReturn, Union

import typing_extensions


def func1() -> NoReturn:
raise Exception

def func2() -> Union[None, NoReturn]:
pass

def func3() -> Union[None, "NoReturn"]:
pass

def func4() -> Union[None, typing.NoReturn]:
pass

def func5() -> Union[None, typing_extensions.NoReturn]:
pass


Alias1 = NoReturn
Alias2 = Callable[..., NoReturn] # [broken-noreturn]
Alias3 = Callable[..., "NoReturn"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[master]
py-version=3.7
load-plugins=pylint.extensions.typing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
broken-noreturn:33:23:33:31::'NoReturn' inside compound types is broken in 3.7.0 / 3.7.1:INFERENCE

0 comments on commit cc7fb08

Please sign in to comment.