Skip to content

Conversation

@kamyarghajar
Copy link
Contributor

Description

This PR fixes a breaking AttributeError: __metadata__ encountered when running injector on Python 3.13.

In Python 3.13, certain type hints (particularly those involving Literal, Union, or classes using slots=True) can be identified as a specialization of Annotated but do not consistently expose the __metadata__ attribute. Direct access to v.__metadata__ now raises an AttributeError in these scenarios, whereas in previous Python versions it would typically return an empty tuple or simply not be triggered in this specific code path.

Changes

Modified the has_injectable_parameters check in injector/__init__.py to use getattr() when accessing __metadata__.

# Before
_inject_marker in v.__metadata__

# After
_inject_marker in getattr(v, "__metadata__", ())

This ensures that if the attribute is missing, the code defaults to an empty tuple, allowing the in check to fail gracefully instead of raising an exception.

@davidparsson
Copy link
Collaborator

Thanks for your contribution! Would you be able to include a test that exposes the problem? The test suite passed on 3.13 before this change.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.54%. Comparing base (c58c7a2) to head (515a1f2).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #304   +/-   ##
=======================================
  Coverage   96.54%   96.54%           
=======================================
  Files           1        1           
  Lines         608      608           
  Branches      103      103           
=======================================
  Hits          587      587           
  Misses         15       15           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@davidparsson
Copy link
Collaborator

davidparsson commented Jan 9, 2026

Oh, I saw your issue just now. I can add a test myself based on that. Thanks again!

@davidparsson davidparsson merged commit 333a0fa into python-injector:master Jan 9, 2026
13 checks passed
@davidparsson
Copy link
Collaborator

Fixes #303

@davidparsson
Copy link
Collaborator

This is released in 0.24.0

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