Skip to content

Complete Python 2 removal and Python 3-only tooling#161

Merged
derek73 merged 5 commits into
masterfrom
drop-python-2-cleanup
Jun 7, 2026
Merged

Complete Python 2 removal and Python 3-only tooling#161
derek73 merged 5 commits into
masterfrom
drop-python-2-cleanup

Conversation

@derek73
Copy link
Copy Markdown
Owner

@derek73 derek73 commented Jun 7, 2026

Follow-up cleanup after #160 dropped Python 2 support (python_requires = '>=3.10'). Removes the now-dead 2/3 compatibility layer, aligns the build tooling and wheel metadata with Python 3-only, and adds Python 3.14 to the supported set.

The code itself needed nothing for 3.11/3.12: it compiles clean under SyntaxWarning-as-error (regexes use raw strings), imports clean under DeprecationWarning-as-error, uses no removed unittest aliases, and the CI matrix / classifiers / .readthedocs.yaml already covered 3.10–3.13. The gaps were in tooling and stale metadata.

Commits

  • Remove Python 2 compatibility code — the sys.version_info fork and u()/text_type/binary_type/text_types shims in util.py (now plain str/bytes); folds the Py2 __unicode__ protocol into __str__; drops from __future__ import unicode_literals and utf-8 coding cookies everywhere; removes the collections.Set ImportError fallback (that path no longer exists in 3.10+); type() == binary_typeisinstance(s, bytes); fixes two Py2-style doctests; rewrites 27 u(...) calls in tests to str(...).
  • Modernize build tooling for Python 3.12+ — distutils was removed from the stdlib in 3.12, so python setup.py sdist is deprecated. CI now uses python -m build --sdist (matching the publish workflow); dropped the dead from distutils.core import setup fallback in setup.py.
  • Remove universal wheel flagsetup.cfg contained only [bdist_wheel] universal = 1, which built a py2.py3-none-any wheel falsely advertising Python 2. Removed; wheels now tag py3-none-any.
  • Remove Python 2 next() iterator aliasesHumanName and SetManager each carried a def next(self): return self.__next__() Py2 shim. Removed; __next__ is kept.
  • Add Python 3.14 support — 3.14 (released Oct 2025) is now the latest stable. Added to the CI matrix and classifiers; suite passes on it. python_requires stays >=3.10 (a floor).

Intentionally preserved

Bytes-input decoding and the encoding parameter — these are real Python 3 functionality, not 2/3 shims.

Verification

  • python tests.py: 342 tests pass (skipped=2, expected failures=10), unchanged from baseline — confirmed on 3.14.
  • python -m build --sdist + twine check: pass in a clean venv.
  • python -m build --wheel: produces nameparser-1.1.3-py3-none-any.whl (was py2.py3-none-any).

Known follow-up (out of scope)

SetManager.__next__ in nameparser/config/__init__.py is dead and broken independent of Python 2 (indexes a set, reads an uninitialized self.count). Left untouched here to keep scope to Py2 shims; worth a separate bug-fix.

🤖 Generated with Claude Code

derek73 and others added 5 commits June 7, 2026 14:05
With Python 2 support dropped (python_requires >=3.10), the 2/3
compatibility layer is dead code. This removes:

- util.py: the sys.version_info fork and the u/text_type/binary_type/
  text_types shims (now just str/bytes builtins); dead NullHandler
  AttributeError fallback
- parser.py: import sys and two version_info branches; folds the Py2
  __unicode__ protocol into __str__; replaces u()/text_types/binary_type
  with str/(str, bytes)/bytes
- config/__init__.py: the collections.abc Set ImportError fallback (the
  collections.Set path no longer exists in 3.10+); type() == binary_type
  -> isinstance(s, bytes); fixes two Py2-style doctests
- all modules: from __future__ import unicode_literals and utf-8 coding
  cookies (both no-ops in Py3)
- tests.py: 27 u(...) calls -> str(...)

Bytes-input decoding and the encoding parameter are intentionally kept
as real Py3 functionality. All 342 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
distutils was removed from the stdlib in 3.12, so the legacy build path
is deprecated. Align the test workflow with the publish workflow:

- CI: replace `python setup.py sdist` with `python -m build --sdist`
  (and install `build`), matching the publish workflow
- setup.py: drop the dead `from distutils.core import setup` fallback;
  setuptools is guaranteed for any modern build

Verified `python -m build --sdist` + `twine check` succeed in a clean venv.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
setup.cfg contained only `[bdist_wheel] universal = 1`, which built a
py2.py3-none-any wheel advertising Python 2 compatibility that no longer
exists. With the flag gone, bdist_wheel tags the wheel py3-none-any by
default under Python 3 — matching python_requires >=3.10.

Verified: `python -m build --wheel` now produces
nameparser-1.1.3-py3-none-any.whl (was py2.py3-none-any).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Python 2 spelled the iterator protocol method next(); Python 3 uses
__next__(). HumanName and SetManager each carried a `def next(self):
return self.__next__()` forwarding alias to work under both. Nothing in
Python 3 calls .next(), so the aliases are dead.

The __next__() methods are kept (HumanName's drives iteration via
" ".join(self)). SetManager's __next__ is separately broken/dead but
left untouched here to keep this commit scoped to the Py2 shims.

All 342 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Python 3.14 was released October 2025 and is now the latest stable.
Add it to the CI test matrix and the PyPI classifiers. The test suite
passes on 3.14 (342 tests, OK with skipped=2, expected failures=10).

python_requires remains >=3.10 — it is a floor, so newer versions are
already permitted; only the matrix (testing) and classifiers
(advertising) need the bump.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@derek73 derek73 merged commit e9fd487 into master Jun 7, 2026
5 checks passed
@derek73 derek73 deleted the drop-python-2-cleanup branch June 7, 2026 21:31
@derek73 derek73 mentioned this pull request Jun 7, 2026
@derek73 derek73 self-assigned this Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant