Skip to content

Commit d4553ca

Browse files
committed
Use Y069 and return Y050
1 parent 922bb70 commit d4553ca

6 files changed

Lines changed: 18 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ flake8-pyi uses Calendar Versioning (CalVer).
44

55
## Unreleased
66

7-
### Breaking Changes
7+
### New Error Codes
8+
9+
* Y069: Flags imports of `typing.NoReturn` and `typing_extensions.NoReturn`
10+
as they are now unconditionally deprecated.
11+
12+
### Removed Error Codes
813

9-
* Y050: Now flags imports of `typing.NoReturn` and `typing_extensions.NoReturn`
10-
as it is now unconditionally deprecated.
14+
* Y050: Old error code that flagged `typing.NoReturn` and
15+
`typing_extensions.NoReturn` in argument positions only.
1116

1217
### Other changes
1318

ERRORCODES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ The following warnings are currently emitted by default:
6363
| <a id="Y047" href="#Y047">Y047</a> | A private `TypeAlias` should be used at least once in the file in which it is defined. | Redundant code
6464
| <a id="Y048" href="#Y048">Y048</a> | Function bodies should contain exactly one statement. This is because stub files are never executed at runtime, so any more than one statement would be redundant. (Note that if a function body includes a docstring, the docstring counts as a "statement".) | Understanding stubs
6565
| <a id="Y049" href="#Y049">Y049</a> | A private `TypedDict` should be used at least once in the file in which it is defined. | Redundant code
66-
| <a id="Y050" href="#Y050">Y050</a> | Prefer `typing_extensions.Never` over `typing.NoReturn`. | Style
6766
| <a id="Y051" href="#Y051">Y051</a> | Y051 detects redundant unions between `Literal` types and builtin supertypes. For example, `Literal[5]` is redundant in the union `int \| Literal[5]`, and `Literal[True]` is redundant in the union `Literal[True] \| bool`. | Redundant code
6867
| <a id="Y052" href="#Y052">Y052</a> | Y052 disallows assignments to constant values where the assignment does not have a type annotation. For example, `x = 0` in the global namespace is ambiguous in a stub, as there are four different types that could be inferred for the variable `x`: `int`, `Final[int]`, `Literal[0]`, or `Final[Literal[0]]`. Enum members are excluded from this check, as are various special assignments such as `__all__` and `__match_args__`. | Correctness
6968
| <a id="Y053" href="#Y053">Y053</a> | Only string and bytes literals <=50 characters long are permitted. (There are some exceptions, such as `Literal` subscripts, metadata strings inside `Annotated` subscripts, and strings passed to `@deprecated`.) | Style
@@ -82,6 +81,7 @@ The following warnings are currently emitted by default:
8281
| <a id="Y066" href="#Y066">Y066</a> | When using if/else with `sys.version_info`, put the code for new Python versions first. | Style
8382
| <a id="Y067" href="#Y067">Y067</a> | Don't use `Incomplete \| None = None` in argument annotations. Instead, just use `=None`. | Style
8483
| <a id="Y068" href="#Y068">Y068</a> | Don't use `@override` in stub files. Problems with a function signature deviating from its superclass are inherited from the implementation, and other tools such as stubtest are better placed to recognize deviations between stubs and the implementation. | Understanding stubs
84+
| <a id="Y069" href="#Y069">Y069</a> | Prefer `typing_extensions.Never` over `typing.NoReturn`. | Style
8585

8686
## Warnings disabled by default
8787

flake8_pyi/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class Error(NamedTuple):
9090
Y047 = 'Y047 Type alias "{alias_name}" is not used'
9191
Y048 = "Y048 Function body should contain exactly one statement"
9292
Y049 = 'Y049 TypedDict "{typeddict_name}" is not used'
93-
Y050 = 'Y050 Use "typing_extensions.Never" instead of "{module}.NoReturn"'
9493
Y051 = 'Y051 "{literal_subtype}" is redundant in a union with "{builtin_supertype}"'
9594
Y052 = 'Y052 Need type annotation for "{variable}"'
9695
Y053 = "Y053 String and bytes literals >50 characters long are not permitted"
@@ -126,6 +125,7 @@ class Error(NamedTuple):
126125
)
127126
Y067 = 'Y067 Use "=None" instead of "Incomplete | None = None"'
128127
Y068 = 'Y068 Do not use "@override" in stub files.'
128+
Y069 = 'Y069 Use "typing_extensions.Never" instead of "{module}.NoReturn"'
129129

130130
Y090 = (
131131
'Y090 "{original}" means '

flake8_pyi/visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ def _check_import_or_attribute(
810810
if object_name == "Text":
811811
return errors.Y039.format(module=module_name)
812812

813-
# Y050 errors
813+
# Y069 errors
814814
if object_name == "NoReturn":
815-
return errors.Y050.format(module=module_name)
815+
return errors.Y069.format(module=module_name)
816816

817817
# Y023 errors
818818
if module_name == "typing_extensions":

tests/imports.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ from typing import AbstractSet # Y038 Use "from collections.abc import Set as A
153153
from typing_extensions import AbstractSet # Y038 Use "from collections.abc import Set as AbstractSet" instead of "from typing_extensions import AbstractSet" (PEP 585 syntax)
154154
from typing import Text # Y039 Use "str" instead of "typing.Text"
155155
from typing_extensions import Text # Y039 Use "str" instead of "typing_extensions.Text"
156-
from typing import NoReturn # Y050 Use "typing_extensions.Never" instead of "typing.NoReturn"
157-
from typing_extensions import NoReturn # Y050 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
156+
from typing import NoReturn # Y069 Use "typing_extensions.Never" instead of "typing.NoReturn"
157+
from typing_extensions import NoReturn # Y069 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
158158
from typing import ByteString # Y057 Do not use typing.ByteString, which has unclear semantics and is deprecated
159159
from collections.abc import ByteString # Y057 Do not use collections.abc.ByteString, which has unclear semantics and is deprecated
160160

tests/never_vs_noreturn.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# isort: skip_file
22
import typing
33

4-
from typing import NoReturn # Y050 Use "typing_extensions.Never" instead of "typing.NoReturn"
4+
from typing import NoReturn # Y069 Use "typing_extensions.Never" instead of "typing.NoReturn"
55

66
import typing_extensions
77
from typing_extensions import Never
8-
from typing_extensions import NoReturn as NR # Y050 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
8+
from typing_extensions import NoReturn as NR # Y069 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
99

1010
# NoReturn is now flagged at import time, so it should never be flagged elsewhere.
1111

1212
x: NR
1313

1414
def badfunc0(arg: NoReturn) -> None: ...
15-
def badfunc1(*args: typing.NoReturn) -> None: ... # Y050 Use "typing_extensions.Never" instead of "typing.NoReturn"
16-
def badfunc2(**kwargs: typing_extensions.NoReturn) -> None: ... # Y050 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
15+
def badfunc1(*args: typing.NoReturn) -> None: ... # Y069 Use "typing_extensions.Never" instead of "typing.NoReturn"
16+
def badfunc2(**kwargs: typing_extensions.NoReturn) -> None: ... # Y069 Use "typing_extensions.Never" instead of "typing_extensions.NoReturn"
1717
def badfunc3(*, arg: NoReturn) -> None: ...
1818
def badfunc4() -> NoReturn: ...
1919

0 commit comments

Comments
 (0)