Skip to content

fix!: Replace Python 2-style ABC patterns with Python 3 equivalents#430

Merged
jsonbailey merged 2 commits into
mainfrom
jb/sdk-py2-deprecations/fix-abc-metaclass
Jun 5, 2026
Merged

fix!: Replace Python 2-style ABC patterns with Python 3 equivalents#430
jsonbailey merged 2 commits into
mainfrom
jb/sdk-py2-deprecations/fix-abc-metaclass

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

@jsonbailey jsonbailey commented Jun 4, 2026

Summary

  • Replace __metaclass__ = ABCMeta class-body assignments (Python 2-only, silently ignored in Python 3) with proper (ABC) base class inheritance across 4 modules and 11 classes.
  • Replace @abstractproperty decorators (deprecated since Python 3.3) with the correct @property + @abstractmethod stacking in 7 locations across 4 files.
  • Remove now-unused ABCMeta and abstractproperty from all from abc import ... lines.

Files changed

File Changes
ldclient/interfaces.py 11 classes: __metaclass__(ABC); 5 @abstractproperty@property + @abstractmethod
ldclient/hook.py Hook class + metadata property
ldclient/plugin.py Plugin class
ldclient/migrations/migrator.py Migrator class
ldclient/testing/integrations/persistent_feature_store_test_base.py tester_class property
ldclient/testing/integrations/big_segment_store_test_base.py tester_class property

Why

In Python 3, __metaclass__ = ABCMeta inside a class body is a no-op — the metaclass is never applied, so @abstractmethod decorators were not enforced. Using (ABC) as a base class is the correct Python 3 pattern and actually enforces the abstract interface.

@abstractproperty has been deprecated since Python 3.3 and emits DeprecationWarning in newer Python versions. The correct replacement is to stack @property on top of @abstractmethod.

Test plan

  • make test — 1005 passed, 194 skipped (database integration tests, expected)

🤖 Generated with Claude Code


Note

Medium Risk
Marked breaking because stricter ABC enforcement can surface at runtime if custom subclasses omitted required abstract members; behavior of complete implementations should be unchanged.

Overview
Replaces legacy Python 2 abstract-base patterns with idiomatic Python 3 across SDK interfaces, hooks, plugins, migrations, and integration test bases.

__metaclass__ = ABCMeta is removed in favor of inheriting (ABC) on classes such as FeatureStore, Hook, Plugin, Migrator, and related ldclient.interfaces types, so @abstractmethod is actually enforced at instantiation time. @abstractproperty is replaced with @property + @abstractmethod on abstract properties like Hook.metadata, FeatureStore.initialized, and test-base tester_class. Imports drop unused ABCMeta / abstractproperty.

Contract test PostingHook now implements metadata so it stays a valid Hook subclass under the stricter ABC rules.

Reviewed by Cursor Bugbot for commit 3162cfa. Bugbot is set up for automated code reviews on this repo. Configure here.

Tracked Internally: SDK-2463

Replace `__metaclass__ = ABCMeta` class-body assignments with `(ABC)` base
class inheritance, and replace `@abstractproperty` decorators (deprecated since
Python 3.3) with the correct `@property` + `@abstractmethod` stacking.

Files changed:
- ldclient/interfaces.py: 11 classes updated, 5 @abstractproperty replaced
- ldclient/hook.py: Hook class updated, metadata @abstractproperty replaced
- ldclient/plugin.py: Plugin class updated
- ldclient/migrations/migrator.py: Migrator class updated
- ldclient/testing/integrations/persistent_feature_store_test_base.py: tester_class @abstractproperty replaced
- ldclient/testing/integrations/big_segment_store_test_base.py: tester_class @abstractproperty replaced

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsonbailey jsonbailey requested a review from a team as a code owner June 4, 2026 15:52
@jsonbailey jsonbailey changed the title fix: Replace Python 2-style ABC patterns with Python 3 equivalents fix!: Replace Python 2-style ABC patterns with Python 3 equivalents Jun 4, 2026
@abstractproperty was not strictly enforcing the abstract contract, so
PostingHook could be instantiated without implementing metadata. With
@Property + @AbstractMethod Python raises TypeError at instantiation time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsonbailey jsonbailey merged commit 22b8fe5 into main Jun 5, 2026
24 of 25 checks passed
@jsonbailey jsonbailey deleted the jb/sdk-py2-deprecations/fix-abc-metaclass branch June 5, 2026 18:00
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