Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

add tuple check to style_checker #530

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions style_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
a.transpose((2, 0, 1)) # OK
a.reshape(2, 0, 1) # NG

- Initialization of empty `list`/`dict`.
An empty `list`/`dict` should be initialized by `[]`/`{}`.
- Initialization of empty `list`/`dict`/`tuple`.
An empty `list`/`dict`/`tuple` should be initialized by `[]`/`{}`/`()`.

Example:
a = [] # OK
b = {} # OK
c = () # OK

a = list() # NG
b = dict() # NG
c = tuple() # NG
"""

import argparse
Expand Down Expand Up @@ -114,6 +116,15 @@ def check_empty_dict(node):
yield (node.lineno, 'init by dict()')


def check_empty_tuple(node):
if not isinstance(node, ast.Call):
return
if not isinstance(node.func, ast.Name):
return
if node.func.id == 'tuple' and len(node.args) == 0:
yield (node.lineno, 'init by tuple()')


def main():
parser = argparse.ArgumentParser()
parser.add_argument('dir')
Expand Down