-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ast | ||
from typing import List, Sequence | ||
|
||
|
||
def normalize_dict_elements(node: ast.Dict) -> Sequence[ast.AST]: | ||
""" | ||
Normalizes ``dict`` elements and enforces consistent order. | ||
We had a problem that some ``dict`` objects might not have some keys. | ||
Example:: | ||
some_dict = {**one, **two} | ||
This ``dict`` contains two values and zero keys. | ||
This function will normalize this structure to use | ||
values instead of missing keys. | ||
See also: | ||
https://github.com/wemake-services/wemake-python-styleguide/issues/450 | ||
""" | ||
elements: List[ast.AST] = [] | ||
for dict_key, dict_value in zip(node.keys, node.values): | ||
if dict_key is None: | ||
elements.append(dict_value) | ||
else: | ||
elements.append(dict_key) | ||
return elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters