File tree Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ Semantic versioning in our case means:
1717 change the client facing API, change code conventions significantly, etc.
1818
1919
20+ ## WIP
21+
22+ ### Misc
23+
24+ - Minor refactoring ` wemake_python_styleguide.logic.naming.enums.has_enum_like_base_with_config ` , #3518
25+ - Improves ` --known-enum-bases ` option help text and documentation, #3518
26+
27+
2028## 1.4.0
2129
2230### Features
Original file line number Diff line number Diff line change @@ -86,9 +86,13 @@ def has_enum_like_base_with_config(
8686
8787 enum_bases = config .known_enum_bases
8888 if enum_bases :
89- normalized : tuple [str , ...] = tuple ({
90- name for base in enum_bases for name in (base , base .split ('.' )[- 1 ])
91- })
92- return _has_one_of_base_classes (defn , normalized )
89+ return _has_one_of_base_classes (
90+ defn ,
91+ tuple ({
92+ name
93+ for base in enum_bases
94+ for name in (base , base .split ('.' )[- 1 ])
95+ }),
96+ )
9397
9498 return False
Original file line number Diff line number Diff line change @@ -289,8 +289,7 @@ class Configuration:
289289 _Option (
290290 '--known-enum-bases' ,
291291 defaults .KNOWN_ENUM_BASES ,
292- 'List of additional enum-like base class names that should be '
293- 'treated as enums.' ,
292+ 'List of additional enum-like base class names.' ,
294293 type = String ,
295294 comma_separated_list = True ,
296295 ),
Original file line number Diff line number Diff line change @@ -453,6 +453,20 @@ class UpperCaseAttributeViolation(ASTViolation):
453453 Default:
454454 :str:`wemake_python_styleguide.options.defaults.KNOWN_ENUM_BASES`
455455
456+ You can configure custom enum-like base classes that should be treated
457+ as enums:
458+
459+ .. code:: ini
460+
461+ [flake8]
462+ known-enum-bases = BaseEnum, constants.AnotherBaseEnum
463+
464+ Or via command line:
465+
466+ .. code:: bash
467+
468+ flake8 --known-enum-bases=BaseEnum,constants.AnotherBaseEnum ./
469+
456470 Example::
457471
458472 # Correct:
@@ -465,6 +479,14 @@ class Color(enum.Enum):
465479 WHITE = 0
466480 LIGHT_GRAY = 1
467481
482+ # Correct with `--known-enum-bases=BaseEnum` option:
483+ class BaseEnum(enum.Enum):
484+ pass
485+
486+ class MyEnum(BaseEnum):
487+ HELLO = 'hello'
488+ WORLD = 'world'
489+
468490 # Wrong:
469491 class A:
470492 MY_CONSTANT = 42
You can’t perform that action at this time.
0 commit comments