Skip to content

Python 3 planning

Paul McGuire edited this page Jul 22, 2019 · 9 revisions

Which Python 3 version will be targeted? For instance, if f-strings are used, then this will preclude use by Py3 prior to 3.6. At this time, my plan is to target 3.5 for core pyparsing implementation. This will require those on Py3.0-3.4 to use the legacy 2.4.1 release. I don't believe any of the 3.6 and later features pose a real advantage in core pyparsing code. We do need to ensure that pyparsing will work on these later versions (accessing parse results by name in f-strings, for example). So we may need to have some unit tests that run under 3.6 and later versions.

Desired Python 3 features:

  • use of nonlocal (3.0)
  • except exceptiontype as var: (3.0)
  • use of super() without arguments (3.0)
  • OrderedDict (3.1)
  • autonumbered str.format {} placeholders (3.1)
  • str.format_map (3.2)
  • callable() builtin (3.2)
  • yield from (3.3)
  • raise Exception from None to abbreviate exception tracebacks (3.3)
  • function __qualname__ (3.3)
  • types.SimpleNamespace (3.3)
  • ipaddress module (3.3)
  • enum module (3.4)
  • pathlib module (3.4)
  • infix @ operator (3.5)
  • typing module (3.5)
  • collections.abc.Generator (3.5)
  • f-strings (3.6)
  • '_' in numeric literals and formats (3.6)
  • __init_subclass__ (3.6)
  • enum auto() numbering (3.6)
  • functools.singledispatch (method signature overrides) (3.6)
  • dataclasses (3.7)
  • postponed annotation eval (future) (3.7)
  • Forced UTF-8 runtime mode (3.7)
  • breakpoint() builtin (3.7)
  • module __getattr__
  • contextlib.nullcontext() (3.7)

Conversion of examples?

  • can be done any time, backward compatibility of examples is not a requirement
  • if examples use a later Python feature, should use future import or do upfront Py version validation
  • any examples that have Py2/Py3 compatibility code will drop Py2 code

Py2 compatibility code to be deleted:

  • setup.py versions
  • TravisCI test versions
  • review docstrings for Py2 compatibilities
  • iterkeys, itervalues, iteritems in ParseResults
  • embedded implementation of OrderedDict
  • _ustr()
  • _MAX_INT
  • import compatibility try-excepts
  • unicode string literals (u"lskdjjf")
  • __nonzero__
  • super(type, self) -> just plain super()
  • numbered str.format {} placeholders
  • nonlocal-less version of _trim_arity
  • Py2/Py3 compatibility in unitTests.py, other examples