[feaLib.parser] keep supporting (deprecated) glyphMap argument
so we don't break backward compatibility if user code has Parser(path, glyphMap=...)
This commit is contained in:
parent
e8535f2280
commit
99aa8b0c66
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user