Skip to content

Fix AttributeError on Python 3.9 when invalid type passed to attributes#4933

Open
thakoreh wants to merge 2 commits intoopen-telemetry:mainfrom
thakoreh:fix-python39-attribute-error
Open

Fix AttributeError on Python 3.9 when invalid type passed to attributes#4933
thakoreh wants to merge 2 commits intoopen-telemetry:mainfrom
thakoreh:fix-python39-attribute-error

Conversation

@thakoreh
Copy link

Description

Fixes issue #4821 - Incorrect error when passing wrong attribute type on Python 3.9

The issue is that on Python 3.9, and don't have attribute, which causes an instead of the expected when an invalid type is passed.

Changes

  • Added helper function that handles typing module edge cases
  • Updated error message to use instead of direct access

Root Cause

The fix uses and falls back to or for typing module types.

Test

The fix can be verified by running:

Before fix:
After fix:

Add _get_type_name helper to handle typing module types that don't have
__name__ attribute on Python 3.9 (like Sequence, Mapping).

Fixes: open-telemetry#4821
@thakoreh thakoreh requested a review from a team as a code owner February 24, 2026 14:03
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 24, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@thakoreh
Copy link
Author

The CI is failing because no CHANGELOG entry was added. You can either:

  1. Add a changelog entry to the appropriate CHANGELOG.md file
  2. Add the "Skip Changelog" label if this change doesn't require a changelog entry

This looks like a bug fix, so a changelog entry would be appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

1 participant