unified-font-object / ufoNormalizer

A tool that will normalize the XML and other data inside of a UFO.
Other
51 stars 19 forks source link

plistlib changed in Python 3.9: use_builtin_types removed #73

Closed spl closed 3 years ago

spl commented 3 years ago

See this change and this (abbreviated) error message:

Traceback (most recent call last):
  File "/.../file.py", line 35, in <module>
    normalizeUFO(ufo_path, writeModTimes=False)
  File "/.../lib/python3.9/site-packages/ufonormalizer.py", line 184, in normalizeUFO
    metaInfo = subpathReadPlist(ufoPath, "metainfo.plist")
  File "/.../lib/python3.9/site-packages/ufonormalizer.py", line 1472, in subpathReadPlist
    return _loads(data)
  File "/.../lib/python3.9/site-packages/ufonormalizer.py", line 120, in _loads
    return plistlib.loads(data, use_builtin_types=False)
TypeError: loads() got an unexpected keyword argument 'use_builtin_types'

I removed use_builtin_types and didn't get an error, but I don't know if this is the correct thing to do:

@@ -117,7 +117,7 @@
 if hasattr(plistlib, "loads"):

     def _loads(data):
-        return plistlib.loads(data, use_builtin_types=False)
+        return plistlib.loads(data)

     def _dumps(plist):
         return plistlib.dumps(plist)
spl commented 3 years ago

See also:

josh-hadley commented 3 years ago

We're running into this in AFDKO as we begin to incorporate Python 3.9 in our test suite.

I also played around with simply removing use_builtin_types=False from _loads(), but the test suite has other failures because the deprecation also removed the plistlib.Data class and some other stuff that is used in ufoNormalizer.

A somewhat straightforward workaround would be to copy the pre-Python 3.9 plistlib.Data class definition & friends into ufoNormalizer and switch references from plistlib.Data to ufoNormalizer.Data. All existing functionality using that class within ufoNormalizer would be maintained without a lot of code & test changes.

But the advice regarding the deprecation is to "use bytes" instead of Data. On the surface that is simple enough, but I suspect that other projects that depend on ufoNormalizer might encounter problems.

I can take a stab at a patch, if the maintainers could advise as to any preference on how to work this out.

justvanrossum commented 3 years ago

Perhaps switching to fontTools.misc.plistlib is worth considering?

anthrotype commented 3 years ago

I would prefer to also deprecate that API in fontTools.misc.plistlib. I don't see the point now that everything is python3 to not use bytes as binary data and str as text.

SolarAquarion commented 3 years ago

@josh-hadley use ufolib2?

anthrotype commented 3 years ago

the fix is to drop support for py27 and not use use_builtin_types argument any more