diff --git a/Lib/fontTools/feaLib/parser.py b/Lib/fontTools/feaLib/parser.py index 631165dfe..7902773f2 100644 --- a/Lib/fontTools/feaLib/parser.py +++ b/Lib/fontTools/feaLib/parser.py @@ -17,7 +17,19 @@ class Parser(object): extensions = {} ast = ast - def __init__(self, featurefile, glyphNames): + def __init__(self, featurefile, glyphNames=(), **kwargs): + if "glyphMap" in kwargs: + from fontTools.misc.loggingTools import deprecateArgument + deprecateArgument("glyphMap", "use 'glyphNames' (iterable) instead") + if glyphNames: + raise TypeError("'glyphNames' and (deprecated) 'glyphMap' are " + "mutually exclusive") + glyphNames = kwargs.pop("glyphMap") + if kwargs: + raise TypeError("unsupported keyword argument%s: %s" + % ("" if len(kwargs) == 1 else "s", + ", ".join(repr(k) for k in kwargs))) + self.glyphNames_ = set(glyphNames) self.doc_ = self.ast.FeatureFile() self.anchors_ = SymbolTable() diff --git a/Tests/feaLib/parser_test.py b/Tests/feaLib/parser_test.py index fd053a776..b9606406c 100644 --- a/Tests/feaLib/parser_test.py +++ b/Tests/feaLib/parser_test.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from fontTools.feaLib.error import FeatureLibError from fontTools.feaLib.parser import Parser, SymbolTable from fontTools.misc.py23 import * +import warnings import fontTools.feaLib.ast as ast import os import unittest @@ -51,6 +52,25 @@ class ParserTest(unittest.TestCase): if not hasattr(self, "assertRaisesRegex"): self.assertRaisesRegex = self.assertRaisesRegexp + def test_glyphMap_deprecated(self): + glyphMap = {'a': 0, 'b': 1, 'c': 2} + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + parser = Parser(UnicodeIO(), glyphMap=glyphMap) + + self.assertEqual(len(w), 1) + self.assertEqual(w[-1].category, UserWarning) + self.assertIn("deprecated", str(w[-1].message)) + self.assertEqual(parser.glyphNames_, {'a', 'b', 'c'}) + + self.assertRaisesRegex( + TypeError, "mutually exclusive", + Parser, UnicodeIO(), ("a",), glyphMap={"a": 0}) + + self.assertRaisesRegex( + TypeError, "unsupported keyword argument", + Parser, UnicodeIO(), foo="bar") + def test_comments(self): doc = self.parse( """ # Initial