Skip to content

Object of type "None" is not subscriptable #4569

Open

Description

@tekumara

Describe your environment

sdk 1.32.1

What happened?

errors in vscode/pyright with

Object of type "None" is not subscriptablePylance[reportOptionalSubscript](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportOptionalSubscript)

Image

Steps to Reproduce

print(span.attributes["name"])

Expected Result

No type error because span.attributes can never be None.

Actual Result

Object of type "None" is not subscriptablePylance[reportOptionalSubscript](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportOptionalSubscript)

Additional context

No response

Would you like to implement a fix?

None

Activity

  1. exekis commented on Jul 20, 2025

    @exekis

    Hi @tekumara, this is a static type issue and not a bug from Otel since span.attributes is likely typed as Optional[dict] so pyright complains even if it’s never None at runtime. If the SDK guarantees it's always a dict then the annotation should be updated. If not then users need to guard with assert span.attributes is not None.

  2. tekumara commented on Jul 20, 2025

    @tekumara
    Author

    Yep I haven't found a code path where it is ever None in the SDK so I'm hoping the type hint can be updated to avoid applications having to always guard.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions