From 701c72116dff53a4e827d41fd72108437f94f4c9 Mon Sep 17 00:00:00 2001 From: Sascha Brawer Date: Fri, 4 Sep 2015 16:22:16 +0200 Subject: [PATCH] [feaLib] Make feaLib compliant with the PEP8 style guide After this change, pep8 v1.6.2 reports no style guide violations. --- Lib/fontTools/feaLib/lexer_test.py | 7 ++++--- Lib/fontTools/feaLib/parser.py | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/feaLib/lexer_test.py b/Lib/fontTools/feaLib/lexer_test.py index 891a27fd9..6feaf9dbc 100644 --- a/Lib/fontTools/feaLib/lexer_test.py +++ b/Lib/fontTools/feaLib/lexer_test.py @@ -80,15 +80,16 @@ class LexerTest(unittest.TestCase): self.assertRaises(FeatureLibError, lambda: lex("123 \u0001")) def test_newline(self): - lines = lambda s: [loc[1] for (_, _, loc) in Lexer(s, "test.fea")] + def lines(s): + return [loc[1] for (_, _, loc) in Lexer(s, "test.fea")] self.assertEqual(lines("FOO\n\nBAR\nBAZ"), [1, 3, 4]) # Unix self.assertEqual(lines("FOO\r\rBAR\rBAZ"), [1, 3, 4]) # Macintosh self.assertEqual(lines("FOO\r\n\r\n BAR\r\nBAZ"), [1, 3, 4]) # Windows self.assertEqual(lines("FOO\n\rBAR\r\nBAZ"), [1, 3, 4]) # mixed def test_location(self): - locs = lambda s: ["%s:%d:%d" % loc - for (_, _, loc) in Lexer(s, "test.fea")] + def locs(s): + return ["%s:%d:%d" % loc for (_, _, loc) in Lexer(s, "test.fea")] self.assertEqual(locs("a b # Comment\n12 @x"), [ "test.fea:1:1", "test.fea:1:3", "test.fea:2:1", "test.fea:2:4" diff --git a/Lib/fontTools/feaLib/parser.py b/Lib/fontTools/feaLib/parser.py index 3a4085f40..f8dcdb7dd 100644 --- a/Lib/fontTools/feaLib/parser.py +++ b/Lib/fontTools/feaLib/parser.py @@ -400,6 +400,11 @@ class Parser(object): except StopIteration: self.next_token_type_, self.next_token_ = (None, None) + @staticmethod + def reverse_string_(s): + """'abc' --> 'bca'""" + return ''.join(reversed(list(s))) + def make_glyph_range_(self, location, start, limit): """("a.sc", "d.sc") --> {"a.sc", "b.sc", "c.sc", "d.sc"}""" result = set() @@ -407,7 +412,8 @@ class Parser(object): raise FeatureLibError( "Bad range: \"%s\" and \"%s\" should have the same length" % (start, limit), location) - rev = lambda s: ''.join(reversed(list(s))) # string reversal + + rev = self.reverse_string_ prefix = os.path.commonprefix([start, limit]) suffix = rev(os.path.commonprefix([rev(start), rev(limit)])) if len(suffix) > 0: