Commit 2100f3cc authored by Akim Demaille's avatar Akim Demaille
Browse files

style: python: prefer ''' to """

git s '"""' "'''"
parent d694d7c4
......@@ -7,9 +7,9 @@ from vcsn_cxx import *
from vcsn_version import *
def _info_to_dict(info):
"""Convert a "key: value" list of lines into a dictionary.
'''Convert a "key: value" list of lines into a dictionary.
Convert Booleans into bool, and likewise for integers.
"""
'''
res = dict()
for l in info.splitlines():
(k, v) = l.split(':')
......@@ -41,12 +41,12 @@ def _is_equal(lhs, rhs):
return isinstance(rhs, lhs.__class__) and str(lhs) == str(rhs)
def _left_mult(self, lhs):
"""Support "aut * weight". Also serves for ratexps."""
'''Support "aut * weight". Also serves for ratexps.'''
return self.left_mult(self.context().weight(str(lhs)))
def _right_mult(self, rhs):
"""Support both "aut * aut" and "aut * weight". Also serves for
ratexps."""
'''Support both "aut * aut" and "aut * weight". Also serves for
ratexps.'''
if isinstance(rhs, type(self)):
return self.concatenate(rhs)
elif isinstance(rhs, weight):
......
......@@ -39,7 +39,7 @@ def _automaton_as_svg(self, format = "dot", engine = "dot"):
automaton.as_svg = _automaton_as_svg
def _automaton_convert(self, mode, engine = "dot"):
"""Display automaton `self` in `mode` with Graphviz `engine`."""
'''Display automaton `self` in `mode` with Graphviz `engine`.'''
from IPython.display import SVG
if mode in ["dot", "tooltip", "transitions"]:
svg = _dot_to_svg(self.dot(mode), engine)
......@@ -56,7 +56,7 @@ def _automaton_convert(self, mode, engine = "dot"):
raise(ValueError("invalid display format: " + mode))
def _automaton_display(self, mode, engine = "dot"):
"""Display automaton `self` in `mode` with Graphviz `engine`."""
'''Display automaton `self` in `mode` with Graphviz `engine`.'''
from IPython.display import display
display(_automaton_convert(self, mode, engine))
......@@ -73,10 +73,10 @@ def _automaton_init(self, text, fmt = "dot"):
automaton.__init__ = lambda *args: _automaton_init(*args)
def _automaton_interact(self):
"""Display automaton `self` with a local menu to the select
'''Display automaton `self` with a local menu to the select
the display mode. Pay attention to not displaying large
automata by default.
"""
'''
from ipython import interact_h
if 20 < self.state_number():
modes = ['info', 'dot']
......@@ -92,9 +92,9 @@ automaton.dot = lambda self, mode = "dot": _dot_pretty(self.format('dot'), mode)
# automaton.eval.
def _automaton_eval(self, w):
"""Evaluation of word `w` on `self`, with possible conversion from
'''Evaluation of word `w` on `self`, with possible conversion from
plain string to genuine label object.
"""
'''
c = self.context()
if not isinstance(w, label):
w = c.word(str(w))
......@@ -175,9 +175,9 @@ def _automaton_is_synchronized_by(self, w):
automaton.is_synchronized_by = _automaton_is_synchronized_by
def _lan_to_lal(a):
"""Convert an automaton from supporting spontaneous transitions
'''Convert an automaton from supporting spontaneous transitions
to not supporting them by modifying its context specification.
"""
'''
dot = a.format('dot')
dot = re.sub(r'"lan<(lal_char\(.*?\))>', r'"\1', dot)
dot = re.sub(r'"lat<lan<(lal_char\(.*?\))>, *lan<(lal_char\(.*?\))>',
......
from vcsn_cxx import automaton
class Conjunction(object):
"""A proxy class that delays calls to the & operator in order
'''A proxy class that delays calls to the & operator in order
to turn a & b & c into a variadic evaluation of
automaton._product(a, b, c).
Based on
http://code.activestate.com/recipes/496741-object-proxying
"""
'''
__slots__ = ["auts", "__weakref__"]
def __init__(self, *args):
object.__setattr__(self, "auts", [args[0]])
......
......@@ -100,9 +100,9 @@ def interact_h(_interact_f, *args, **kwargs):
class table(list):
""" Overridden list class which takes a 2-dimensional list of
''' Overridden list class which takes a 2-dimensional list of
the form [[1,2,3],[4,5,6]], and renders an HTML Table in
IPython Notebook. """
IPython Notebook. '''
def to_html(self, s):
try:
......
......@@ -47,7 +47,7 @@ def rst_file(name, content):
print()
def format(d):
"""Pretty-print `d` into a diffable string."""
'''Pretty-print `d` into a diffable string.'''
if isinstance(d, dict):
return "\n".join(["{}: {}".format(k, format(d[k]))
for k in sorted(d.keys())])
......@@ -139,7 +139,7 @@ def CHECK_EQ(expected, effective, loc = None):
rst_diff(exp, eff)
def CHECK_EQUIV(a1, a2):
"""Check that `a1` and `a2` are equivalent."""
'''Check that `a1` and `a2` are equivalent.'''
num = 10
a1 = a1.strip()
a2 = a2.strip()
......
......@@ -17,7 +17,7 @@ def check(exp, aut):
def check_context(exp, aut, ctx):
check(exp, aut.replace('CTX', ctx))
a = """
a = '''
digraph
{
vcsn_context = "CTX"
......@@ -29,20 +29,20 @@ digraph
2 -> 1 [label = "a"]
2 -> 2 [label = "b"]
1 -> F1
}"""
}'''
for ls in ["lal", "lan", "law"]:
for ws in ["b", "z"]:
check_context(True, a, ls + "_char(ab)_" + ws)
a = """
a = '''
digraph
{
vcsn_context = "CTX"
I0 -> 0
0 -> 1 [label = "\\\\e, a"]
1 -> F1
}"""
}'''
for ls in ["lan", "law"]:
......@@ -50,7 +50,7 @@ for ls in ["lan", "law"]:
check_context(False, a, ls + "_char(ab)_" + ws)
# Tuples of lan
a = """
a = '''
digraph
{
vcsn_context = "lat<lan_char(ab), lan_char(xy)>_b"
......@@ -60,11 +60,11 @@ digraph
1 -> 2 [label = "(\\\\e, y)"]
2 -> 1 [label = "(b, \\\\e)"]
1 -> F1
}"""
}'''
check(True, a)
a = """
a = '''
digraph
{
vcsn_context = "lat<lan_char(ab), lan_char(xy)>_b"
......@@ -75,12 +75,12 @@ digraph
2 -> 1 [label = "(b, \\\\e)"]
2 -> 1 [label = "(\\\\e, \\\\e)"]
1 -> F1
}"""
}'''
check(False, a)
# Tuple of lal x lan
a = """
a = '''
digraph
{
vcsn_context = "lat<lal_char(ab), lan_char(xy)>_b"
......@@ -90,6 +90,6 @@ digraph
1 -> 2 [label = "(b, y)"]
2 -> 1 [label = "(b, \\\\e)"]
1 -> F1
}"""
}'''
check(True, a)
......@@ -9,8 +9,8 @@ ctx = vcsn.context("lal_char(abcd)_b")
## Complement. ##
## ------------ ##
def check_complement(r1):
"""Check that `complement` on a rational expression corresponds to
its concrete syntax."""
'''Check that `complement` on a rational expression corresponds to
its concrete syntax.'''
eff = ctx.ratexp(r1).complement()
exp = ctx.ratexp('({}){{c}}'.format(r1))
CHECK_EQ(exp, eff)
......@@ -22,8 +22,8 @@ check_complement('ab')
## Concat. ##
## -------- ##
def check_concat(r1, r2):
"""Check that `*` between rational expression corresponds to
concatenation concrete syntax."""
'''Check that `*` between rational expression corresponds to
concatenation concrete syntax.'''
eff = ctx.ratexp(r1) * ctx.ratexp(r2)
exp = ctx.ratexp('({})({})'.format(r1, r2))
CHECK_EQ(exp, eff)
......@@ -41,8 +41,8 @@ check_concat('a', '\z')
## Difference. ##
## ------------ ##
def check_difference(r1, r2):
"""Check that `%` between rational expression corresponds to
`%` in concrete syntax."""
'''Check that `%` between rational expression corresponds to
`%` in concrete syntax.'''
eff = ctx.ratexp(r1) % ctx.ratexp(r2)
exp = ctx.ratexp('({})%({})'.format(r1, r2))
CHECK_EQ(exp, eff)
......@@ -60,8 +60,8 @@ check_difference('a', '\z')
## Conjunction. ##
## ------------- ##
def check_conj(r1, r2):
"""Check that `&` between rational expression corresponds to
`&` in concrete syntax."""
'''Check that `&` between rational expression corresponds to
`&` in concrete syntax.'''
eff = ctx.ratexp(r1) & ctx.ratexp(r2)
exp = ctx.ratexp('({})&({})'.format(r1, r2))
CHECK_EQ(exp, eff)
......@@ -79,8 +79,8 @@ check_conj('a', '\z')
## Sum. ##
## ----- ##
def check_sum(r1, r2):
"""Check that `+` between rational expression corresponds to
`+` in concrete syntax."""
'''Check that `+` between rational expression corresponds to
`+` in concrete syntax.'''
eff = ctx.ratexp(r1) + ctx.ratexp(r2)
exp = ctx.ratexp('({})+({})'.format(r1, r2))
CHECK_EQ(exp, eff)
......@@ -99,8 +99,8 @@ check_sum('a', '\z')
## Transposition. ##
## --------------- ##
def check_transposition(r1):
"""Check that `transposition` on a rational expression corresponds to
its concrete syntax."""
'''Check that `transposition` on a rational expression corresponds to
its concrete syntax.'''
eff = ctx.ratexp(r1).transposition()
exp = ctx.ratexp('({}){{T}}'.format(r1))
CHECK_EQ(exp, eff)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment