Skip to content

Commit 0c1b6a2

Browse files
authored
Marks unique enums as @unique (#11181)
All enums in mypy are unique. Eventhough, current state of enum_plugin does not support @unique checking during mypy run, it is a good thing to have. It will raise ValueError: duplicate values found in <enum 'ArgKind'>: CUSTOM -> ARG_NAMED during development if this rule is violated.
1 parent 20fa54a commit 0c1b6a2

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

mypy/modulefinder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import re
1111
import subprocess
1212
import sys
13-
from enum import Enum
13+
from enum import Enum, unique
1414

1515
from typing import Dict, Iterator, List, NamedTuple, Optional, Set, Tuple, Union
1616
from typing_extensions import Final
@@ -41,6 +41,7 @@
4141
# TODO: Consider adding more reasons here?
4242
# E.g. if we deduce a module would likely be found if the user were
4343
# to set the --namespace-packages flag.
44+
@unique
4445
class ModuleNotFoundReason(Enum):
4546
# The module was not found: we found neither stubs nor a plausible code
4647
# implementation (with or without a py.typed file).

mypy/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Abstract syntax tree node classes (i.e. parse tree)."""
22

33
import os
4-
from enum import Enum
4+
from enum import Enum, unique
55
from abc import abstractmethod
66
from mypy.backports import OrderedDict
77
from collections import defaultdict
@@ -1521,7 +1521,7 @@ def accept(self, visitor: ExpressionVisitor[T]) -> T:
15211521

15221522

15231523
# Kinds of arguments
1524-
1524+
@unique
15251525
class ArgKind(Enum):
15261526
# Positional argument
15271527
ARG_POS = 0

mypyc/irbuild/format_str_tokenizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import List, Tuple, Optional
44
from typing_extensions import Final
5-
from enum import Enum
5+
from enum import Enum, unique
66

77
from mypy.checkstrformat import (
88
parse_format_value, ConversionSpecifier, parse_conversion_specifiers
@@ -22,6 +22,7 @@
2222
from mypyc.primitives.str_ops import str_build_op, str_op
2323

2424

25+
@unique
2526
class FormatOp(Enum):
2627
"""FormatOp represents conversion operations of string formatting during
2728
compile time.

0 commit comments

Comments
 (0)