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

Commit

Permalink
Merge pull request #530 from Hakuyume/add-tuple-check-to-style-checker
Browse files Browse the repository at this point in the history
add tuple check to style_checker
  • Loading branch information
yuyu2172 authored Mar 1, 2018
2 parents d879a75 + 4cb14c2 commit 8f5f31f
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit 8f5f31f

Please sign in to comment.