Skip to content

Removing legacy cruft and some basic typing#134

Merged
jamadden merged 4 commits into
masterfrom
typing-py2
May 8, 2026
Merged

Removing legacy cruft and some basic typing#134
jamadden merged 4 commits into
masterfrom
typing-py2

Conversation

@jamadden
Copy link
Copy Markdown
Member

@jamadden jamadden commented May 8, 2026

  • A bunch of Python 2 and Pypy code
  • Add some basic typing to the main public APIs and some internal APIs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes legacy Python 2/PyPy compatibility code and deprecated API parameters, introduces basic type annotations across public/internal APIs (including publishing py.typed and adding a mypy config), and renames the datetime module to datetime_ext (with compatibility shims) to avoid stdlib name conflicts.

Changes:

  • Remove Python 2-era compatibility (e.g., __future__ imports, conditional code paths) and long-deprecated parameters (registry, pre_hook, etc.) across key APIs.
  • Add/adjust type annotations in core modules and Cython .pxd declarations; add py.typed and tool.mypy configuration.
  • Rename nti.externalization.datetimenti.externalization.datetime_ext, update ZCML/docs/tests, and add backward-compat import shims.

Reviewed changes

Copilot reviewed 79 out of 80 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/nti/externalization/zcml.py Adds typing around dynamic class creation in auto-package externalization.
src/nti/externalization/tests/test_zcml.py Removes Py2 __future__ imports; import tidy.
src/nti/externalization/tests/test_testing.py Removes Py2 __future__ imports.
src/nti/externalization/tests/test_singleton.py Removes Py2 __future__ imports; minor import reordering.
src/nti/externalization/tests/test_proxy.py Removes Py2 __future__ imports.
src/nti/externalization/tests/test_persistence.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_oids.py Removes Py2 __future__ imports; minor import ordering cleanup.
src/nti/externalization/tests/test_internalization.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_interfaces.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_integer_strings.py Removes Py2 __future__ imports.
src/nti/externalization/tests/test_factory.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_externalization.py Import reordering; update datetime imports to datetime_ext.
src/nti/externalization/tests/test_dublincore.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_docs.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test_datetime.py Switches tests to datetime_ext APIs while keeping doctest suite for legacy name.
src/nti/externalization/tests/test_datastructures.py Import tidy; update datetime imports to datetime_ext.
src/nti/externalization/tests/test_autopackage.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/test__compat.py Removes Py2 __future__ imports.
src/nti/externalization/tests/benchmarks/profileinterfaces.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/objects.py Removes Py2 __future__ imports; adds a basic type annotation for benchmark object.
src/nti/externalization/tests/benchmarks/interfaces.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/bootstrapinterfaces.py Removes Py2 __future__ imports.
src/nti/externalization/tests/benchmarks/bm_user_profile.py Removes Py2 __future__ imports; removes unused logger.
src/nti/externalization/tests/benchmarks/bm_singleton.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/bm_simple_registered_class.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/bm_simple_iface.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/bm_simple_iface_list.py Removes Py2 __future__ imports; simplifies vmprofile path.
src/nti/externalization/tests/benchmarks/main.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/tests/benchmarks/init.py Removes Py2 __future__ imports.
src/nti/externalization/tests/init.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/testing.py Removes Py2 __future__ imports.
src/nti/externalization/singleton.py Removes Py2 __future__ imports; defines Singleton using modern metaclass syntax; adds typing.
src/nti/externalization/representation.py Removes deprecated registry param; adds casts/typing; removes Py2 YAML representer handling.
src/nti/externalization/py.typed Publishes typing marker for downstream type checkers.
src/nti/externalization/proxy.py Adds typing for proxy unwrapper registry; removes Py2 __future__ imports.
src/nti/externalization/persistence.py Removes Py2 __future__ imports; adds a few type ignores/annotations for fallbacks.
src/nti/externalization/oids.py Removes Py2 __future__ imports; adds typing for parsing/splitting OIDs and db name.
src/nti/externalization/numbers.py Removes Py2 __future__ imports.
src/nti/externalization/internalization/updater.py Adds overloads/typing; removes deprecated registry/pre_hook parameters.
src/nti/externalization/internalization/tests/test_updater.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/internalization/tests/test_fields.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/internalization/tests/test_externals_wo_class_mimetype.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/internalization/legacy_factories.py Removes Py2 __future__ imports; switches to stdlib logging; minor typing tweaks.
src/nti/externalization/internalization/fields.py Removes Py2 string handling; adds typing and refactors exception capture.
src/nti/externalization/internalization/factories.py Removes deprecated registry param; switches to stdlib logging; adds typing.
src/nti/externalization/internalization/externals.py Removes Python 2 fallback import logic; simplifies imports.
src/nti/externalization/internalization/events.py Adds typing for modified-attributes generation and related caches.
src/nti/externalization/internalization/_updater.pxd Updates Cython declarations to match removed deprecated args and typing changes.
src/nti/externalization/internalization/_fields.pxd Updates Cython declarations to match str field names and removed helpers.
src/nti/externalization/internalization/_factories.pxd Updates Cython declarations for removed deprecated registry arg.
src/nti/externalization/internalization/_externals.pxd Fixes Cython declaration typos for MutableSequence / component.
src/nti/externalization/internalization/init.py Removes Py2 __future__ imports.
src/nti/externalization/interfaces.py Adds typing for event kwargs; import ordering cleanup.
src/nti/externalization/integer_strings.py Removes Py2 code paths; adds return type annotations.
src/nti/externalization/factory.py Adds typing for default factory callable; removes Py2 __future__ imports.
src/nti/externalization/externalization/tests/test_externalizer.py Removes Py2 __future__ imports; import ordering cleanup.
src/nti/externalization/externalization/standard_fields.py Switches datetime conversion import to datetime_ext; removes Py2 __future__ imports.
src/nti/externalization/externalization/replacers.py Switches to stdlib logging; removes Py2 __future__ imports.
src/nti/externalization/externalization/fields.py Removes Py2 __future__ imports; removes unused logger.
src/nti/externalization/externalization/externalizer.py Removes deprecated registry arg; adds typing and import cleanup.
src/nti/externalization/externalization/dictionary.py Removes deprecated args; adds typing and import cleanup; returns LocatedExternalDict.
src/nti/externalization/externalization/_standard_fields.pxd Updates Cython types from basestring to str.
src/nti/externalization/externalization/_externalizer.pxd Updates Cython types and removes deprecated registry arg declaration.
src/nti/externalization/externalization/init.py Removes deprecated helper; adds typing assertions for mutation paths and import cleanup.
src/nti/externalization/extension_points.py Removes Py2 __future__ imports.
src/nti/externalization/dublincore.py Removes Py2 __future__ imports; adds type ignores for fallback interfaces.
src/nti/externalization/datetime_ext.py Removes Py2 checks; normalizes input type to str.
src/nti/externalization/datastructures.py Adds typing on key methods; import cleanup and minor assertions.
src/nti/externalization/configure.zcml Updates adapters from .datetime.* to .datetime_ext.*.
src/nti/externalization/autopackage.py Adds typing for key autopackage helper methods and return values.
src/nti/externalization/_threadlocal.py Adds typing/generics to thread-local manager.
src/nti/externalization/_interface_cache.py Adds typing for cache instance set and function return types.
src/nti/externalization/_compat.py Removes PY2/PYPY flags; adds overloads/typing for helpers.
src/nti/externalization/_base_interfaces.py Adds typing on several private API helpers.
src/nti/externalization/init.py Adds compatibility shim mapping nti.externalization.datetime to datetime_ext.
setup.py Bumps dev version to 3.1.0.dev0.
pyproject.toml Bumps minimum Cython; adds tool.mypy configuration.
MANIFEST.in Includes .readthedocs.yml in source distributions.
docs/api/datetime.rst Updates API docs to reference datetime_ext.
CHANGES.rst Updates changelog for 3.1.0 and documents datetime rename/deprecation removals/typing.
Comments suppressed due to low confidence (1)

src/nti/externalization/internalization/_updater.pxd:82

  • _argspec_cacheg and _upsable_updateFromExternalObject_cache look like misspellings of the Python globals (_argspec_cache and _usable_updateFromExternalObject_cache) defined in internalization/updater.py. If this pxd is meant to mirror module globals for cimport/cython optimization, the mismatched names will prevent correct access and can silently break any Cython code that expects the correctly-spelled symbols. Align these names with the actual Python globals (or remove them if they’re not intended to be exported).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/nti/externalization/internalization/fields.py Outdated
Comment thread CHANGES.rst Outdated
Comment thread pyproject.toml Outdated
Comment thread src/nti/externalization/internalization/legacy_factories.py Outdated
Comment thread src/nti/externalization/internalization/legacy_factories.py Outdated
@jamadden jamadden merged commit 8e01518 into master May 8, 2026
18 checks passed
@jamadden jamadden deleted the typing-py2 branch May 8, 2026 18:58
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.

2 participants