Skip to content

Commit

Permalink
Allow simple assignments to None in enum class scopes (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Apr 11, 2024
1 parent 5d0c5eb commit 1279f1e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Unreleased

Bugfixes:
* Fix Y026 false positive: allow simple assignment to `None` in class scopes
if the class is known to be an enum class.

## 24.3.1

New error codes:
Expand Down
2 changes: 1 addition & 1 deletion pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ def _check_for_type_aliases(
isinstance(assignment, ast.Subscript)
or _is_valid_pep_604_union(assignment)
or _is_Any(assignment)
or _is_None(assignment)
or (_is_None(assignment) and not self.visiting_enum_class)
):
new_node = ast.AnnAssign(
target=target,
Expand Down
4 changes: 4 additions & 0 deletions tests/aliases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import array
import builtins
import collections.abc
import enum
import typing
from collections.abc import Mapping
from typing import (
Expand Down Expand Up @@ -86,3 +87,6 @@ _snake_case_alias2: TypeAlias = Literal["whatever"] # Y042 Type aliases should

# check that this edge case doesn't crash the plugin
_: TypeAlias = str | int

class FooEnum(enum.Enum):
BAR = None # shouldn't emit Y026 because it's an assignment in an enum class

0 comments on commit 1279f1e

Please sign in to comment.