Skip to content

Commit 8760ffd

Browse files
committed
minor fixes
1 parent 5f84e1c commit 8760ffd

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

python/TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55

66
- maybe get rid of colons after each attribute in class (and possibly arg in method) docstring - not everything needs to be explained
77

8+
- !!! fix: when creating docstring on class, there are calls on self. methods in the attribute list
9+
fix it as follows, attribute has have an assigned value, Assign.targets[i].Attribute ...
10+
11+
- sort attributes

python/asthelper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def __init__(self, instance_name):
3636
self.instance_name = instance_name
3737

3838
def visit_Attribute(self, node):
39-
try:
39+
if isinstance(node.value, ast.Name):
4040
if node.value.id == self.instance_name:
4141
self.attributes.add(node.attr)
42-
except Exception as e:
43-
pass
42+
else:
43+
self.generic_visit(node)
4444

4545

4646
class MethodVisitor(ast.NodeVisitor):

python/pydocstring.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414

1515
class InvalidSyntax(Exception):
16+
""" Raise when the syntax of processed object is invalid. """
1617
pass
1718

1819

1920
class DocstringUnavailable(Exception):
21+
""" Raise when trying to process object to which there is no docstring. """
2022
pass
2123

2224

2325
class Templater:
26+
2427
def __init__(self, location, indent, style='google'):
2528
self.style = style
2629
self.indent = indent
@@ -88,8 +91,8 @@ def _object_tree(self):
8891

8992
lines.append(first_line)
9093

91-
func_indent = re.findall('^(\s*)', first_line)[0]
92-
expected_indent = concat_(func_indent, self.env.python_indent)
94+
obj_indent = re.findall('^(\s*)', first_line)[0]
95+
expected_indent = concat_(obj_indent, self.env.python_indent)
9396

9497
valid_sig, _ = self._is_valid(first_line)
9598

@@ -107,14 +110,14 @@ def _object_tree(self):
107110
valid_sig, _ = self._is_valid(data)
108111
sig_line = last_row
109112

110-
# remove func_indent from the beginning of all lines
111-
data = '\n'.join([re.sub('^'+func_indent, '', l) for l in lines])
113+
# remove obj_indent from the beginning of all lines
114+
data = '\n'.join([re.sub('^'+obj_indent, '', l) for l in lines])
112115
try:
113116
tree = ast.parse(data)
114117
except Exception as e:
115118
raise InvalidSyntax('Object has invalid syntax.')
116119

117-
return sig_line, func_indent, tree
120+
return sig_line, obj_indent, tree
118121

119122
def _is_correct_indent(self, previous_line, line, expected_indent):
120123
""" Check whether given line has either given indentation (or more)

0 commit comments

Comments
 (0)