Add py.typed file

This commit is contained in:
Nikolaus Waxweiler 2020-09-16 12:03:52 +01:00
parent e1c9710272
commit 863d9fd3c8
4 changed files with 12 additions and 18 deletions

View File

@ -30,7 +30,7 @@ from fontTools.misc.py23 import (
tobytes, tobytes,
) )
# By default, we # By default, we
# - deserialize <data> elements as bytes and # - deserialize <data> elements as bytes and
# - serialize bytes as <data> elements. # - serialize bytes as <data> elements.
# Before, on Python 2, we # Before, on Python 2, we
@ -62,7 +62,7 @@ _date_parser = re.compile(
r"(?::(?P<minute>\d\d)" r"(?::(?P<minute>\d\d)"
r"(?::(?P<second>\d\d))" r"(?::(?P<second>\d\d))"
r"?)?)?)?)?Z", r"?)?)?)?)?Z",
re.ASCII re.ASCII,
) )
@ -162,7 +162,7 @@ PlistEncodable = Union[
class PlistTarget: class PlistTarget:
""" Event handler using the ElementTree Target API that can be """Event handler using the ElementTree Target API that can be
passed to a XMLParser to produce property list objects from XML. passed to a XMLParser to produce property list objects from XML.
It is based on the CPython plistlib module's _PlistParser class, It is based on the CPython plistlib module's _PlistParser class,
but does not use the expat parser. but does not use the expat parser.
@ -407,8 +407,7 @@ def _string_or_data_element(raw_bytes: bytes, ctx: SimpleNamespace) -> etree.Ele
string = raw_bytes.decode(encoding="ascii", errors="strict") string = raw_bytes.decode(encoding="ascii", errors="strict")
except UnicodeDecodeError: except UnicodeDecodeError:
raise ValueError( raise ValueError(
"invalid non-ASCII bytes; use unicode string instead: %r" "invalid non-ASCII bytes; use unicode string instead: %r" % raw_bytes
% raw_bytes
) )
return _string_element(string, ctx) return _string_element(string, ctx)
@ -539,12 +538,8 @@ def load(
""" """
if not hasattr(fp, "read"): if not hasattr(fp, "read"):
raise AttributeError( raise AttributeError("'%s' object has no attribute 'read'" % type(fp).__name__)
"'%s' object has no attribute 'read'" % type(fp).__name__ target = PlistTarget(use_builtin_types=use_builtin_types, dict_type=dict_type)
)
target = PlistTarget(
use_builtin_types=use_builtin_types, dict_type=dict_type
)
parser = etree.XMLParser(target=target) parser = etree.XMLParser(target=target)
result = etree.parse(fp, parser=parser) result = etree.parse(fp, parser=parser)
# lxml returns the target object directly, while ElementTree wraps # lxml returns the target object directly, while ElementTree wraps
@ -608,12 +603,10 @@ def dump(
``ValueError`` ``ValueError``
if non-representable binary data is present if non-representable binary data is present
and `use_builtin_types` is false. and `use_builtin_types` is false.
""" """
if not hasattr(fp, "write"): if not hasattr(fp, "write"):
raise AttributeError( raise AttributeError("'%s' object has no attribute 'write'" % type(fp).__name__)
"'%s' object has no attribute 'write'" % type(fp).__name__
)
root = etree.Element("plist", version="1.0") root = etree.Element("plist", version="1.0")
el = totree( el = totree(
value, value,
@ -632,9 +625,7 @@ def dump(
else: else:
header = XML_DECLARATION + PLIST_DOCTYPE header = XML_DECLARATION + PLIST_DOCTYPE
fp.write(header) fp.write(header)
tree.write( tree.write(fp, encoding="utf-8", pretty_print=pretty_print, xml_declaration=False)
fp, encoding="utf-8", pretty_print=pretty_print, xml_declaration=False
)
def dumps( def dumps(

View File

View File

@ -13,6 +13,8 @@ include *requirements.txt
include tox.ini include tox.ini
include run-tests.sh include run-tests.sh
recursive-include Lib/fontTools py.typed
include .appveyor.yml include .appveyor.yml
include .codecov.yml include .codecov.yml
include .coveragerc include .coveragerc

View File

@ -452,6 +452,7 @@ setup_params = dict(
packages=find_packages("Lib"), packages=find_packages("Lib"),
include_package_data=True, include_package_data=True,
data_files=find_data_files(), data_files=find_data_files(),
zip_safe=False, # So mypy can find typing information.
ext_modules=ext_modules, ext_modules=ext_modules,
setup_requires=setup_requires, setup_requires=setup_requires,
extras_require=extras_require, extras_require=extras_require,