Fonttools: py23 module use within the project

Created on 20 Mar 2021  路  2Comments  路  Source: fonttools/fonttools

I took a quick look into what it would take to part ways with the py23 module imports within the project and it is significant. The following is a ballpark estimate of matched strings in modules under Lib/fontTools/ that does not account for a py23 module import statement in the match. This may be an over count for the strings that are Python builtins/stdlib.

  • basestring: 43 matches across 19 files
  • bytechr: 65 matches across 16 files
  • byteord: 112 matches across 32 files
  • BytesIO: 35 matches across 19 files
  • bytesjoin: 89 matches across 32 files
  • open: 277 matches across 49 files
  • Py23Error: 3 matches in 1 file
  • range: 897 matches across 109 files
  • RecursionError: 4 matches across 2 files
  • round: 302 matches across 50 files
  • SimpleNamespace: 18 matches across 4 files
  • StringIO: 9 matches across 7 files
  • strjoin: 24 matches across 15 files
  • Tag: 744 matches across 47 files
  • tobytes: 70 matches across 37 files
  • tostr: 31 matches across 18 files
  • tounicode: 33 matches across 13 files
  • UnicodeIO: 5 matches across 3 files
  • xrange: 3 matches in 1 file
  • zip: 176 matches across 39 files

Any interest in beginning to chip away at this?

Related #2231


TODO:

  • [x] replace basestring with str #2241
  • [x] replace UnicodeIO with StringIO and import from io module
  • [x] replace tounicode with tostr
  • [x] import BytesIO from io module
  • [x] import SimpleNamespace from types module
  • [ ] move py23.bytechr to new module
  • [ ] move py23.byteord to new module
  • [ ] move py23.bytesjoin to new module
  • [ ] move py23.strjoin to new module
  • [ ] move py23.tobytes to new module
  • [ ] move py23.tostr to new module
  • [ ] move py23.Tag to new module
  • [ ] remove misc.py23 import statements

Most helpful comment

Some of these are easy to fix. basestring should be unconditionally replaced with str, UnicodeIO with StringIO and both should be imported from io module together with BytesIO. SimpleNamespace should be imported from types module.

open, round, range, zip need no change, py23 is already using the Python 3 builtin, so removing the import is all needed.

bytechr, byteord, bytesjoin, strjoin, tobytes, tostr and Tag class seem useful and should probably be moved to a different module (misc.textTools?). tounicode is another name for tostr and should be simply replaced with it.

All 2 comments

Some of these are easy to fix. basestring should be unconditionally replaced with str, UnicodeIO with StringIO and both should be imported from io module together with BytesIO. SimpleNamespace should be imported from types module.

open, round, range, zip need no change, py23 is already using the Python 3 builtin, so removing the import is all needed.

bytechr, byteord, bytesjoin, strjoin, tobytes, tostr and Tag class seem useful and should probably be moved to a different module (misc.textTools?). tounicode is another name for tostr and should be simply replaced with it.

Was this page helpful?
0 / 5 - 0 ratings