diff options
| author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2020-10-08 19:38:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-08 19:38:44 +0300 |
| commit | ebe39ad5d1c4787cf74836c8b453fa4464051a5e (patch) | |
| tree | f6c52ae4a6c8498c9fe501d8e0170981c273350f /python/clippy/__init__.py | |
| parent | 75bc27898db9347ef6ffa4734cfb9f88e25c7b85 (diff) | |
| parent | 74d5f2543c89bdea7b9a3dcb43dd62c38dfd2ed7 (diff) | |
Merge pull request #7260 from qlyoung/reformat-python
Reformat python
Diffstat (limited to 'python/clippy/__init__.py')
| -rw-r--r-- | python/clippy/__init__.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/python/clippy/__init__.py b/python/clippy/__init__.py index 41aeae6b4d..d6865ff484 100644 --- a/python/clippy/__init__.py +++ b/python/clippy/__init__.py @@ -20,11 +20,12 @@ import os, stat import _clippy from _clippy import parse, Graph, GraphNode + def graph_iterate(graph): - '''iterator yielding all nodes of a graph + """iterator yielding all nodes of a graph nodes arrive in input/definition order, graph circles are avoided. - ''' + """ queue = [(graph.first(), frozenset(), 0)] while len(queue) > 0: @@ -42,21 +43,25 @@ def graph_iterate(graph): if n not in stop and n is not node: queue.insert(0, (n, stop, depth + 1)) + def dump(graph): - '''print out clippy.Graph''' + """print out clippy.Graph""" for i, depth in graph_iterate(graph): - print('\t%s%s %r' % (' ' * (depth * 2), i.type, i.text)) + print("\t%s%s %r" % (" " * (depth * 2), i.type, i.text)) + -def wrdiff(filename, buf, reffiles = []): - '''write buffer to file if contents changed''' +def wrdiff(filename, buf, reffiles=[]): + """write buffer to file if contents changed""" - expl = '' - if hasattr(buf, 'getvalue'): + expl = "" + if hasattr(buf, "getvalue"): buf = buf.getvalue() old = None - try: old = open(filename, 'r').read() - except: pass + try: + old = open(filename, "r").read() + except: + pass if old == buf: for reffile in reffiles: # ensure output timestamp is newer than inputs, for make @@ -67,7 +72,7 @@ def wrdiff(filename, buf, reffiles = []): # sys.stderr.write('%s unchanged, not written\n' % (filename)) return - newname = '%s.new-%d' % (filename, os.getpid()) - with open(newname, 'w') as out: + newname = "%s.new-%d" % (filename, os.getpid()) + with open(newname, "w") as out: out.write(buf) os.rename(newname, filename) |
