Skip to content

Commit 1279f1e

Browse files
authored
Allow simple assignments to None in enum class scopes (#479)
1 parent 5d0c5eb commit 1279f1e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
Bugfixes:
6+
* Fix Y026 false positive: allow simple assignment to `None` in class scopes
7+
if the class is known to be an enum class.
8+
39
## 24.3.1
410

511
New error codes:

pyi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ def _check_for_type_aliases(
12191219
isinstance(assignment, ast.Subscript)
12201220
or _is_valid_pep_604_union(assignment)
12211221
or _is_Any(assignment)
1222-
or _is_None(assignment)
1222+
or (_is_None(assignment) and not self.visiting_enum_class)
12231223
):
12241224
new_node = ast.AnnAssign(
12251225
target=target,

tests/aliases.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import array
33
import builtins
44
import collections.abc
5+
import enum
56
import typing
67
from collections.abc import Mapping
78
from typing import (
@@ -86,3 +87,6 @@ _snake_case_alias2: TypeAlias = Literal["whatever"] # Y042 Type aliases should
8687

8788
# check that this edge case doesn't crash the plugin
8889
_: TypeAlias = str | int
90+
91+
class FooEnum(enum.Enum):
92+
BAR = None # shouldn't emit Y026 because it's an assignment in an enum class

0 commit comments

Comments
 (0)