You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object of type "None" is not subscriptablePylance[reportOptionalSubscript](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportOptionalSubscript)
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)
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.
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.
Activity
exekis commentedon Jul 20, 2025
Hi @tekumara, this is a static type issue and not a bug from Otel since
span.attributesis likely typed asOptional[dict]so pyright complains even if it’s neverNoneat runtime. If the SDK guarantees it's always a dict then the annotation should be updated. If not then users need to guard withassert span.attributes is not None.tekumara commentedon Jul 20, 2025
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.
sdk: tighten `ReadableSpan.attributes` to non-Optional `Mapping` (ope…
sdk: tighten `ReadableSpan.attributes` to non-Optional `Mapping` (ope…
sdk: tighten `ReadableSpan.attributes` to non-Optional `Mapping` (ope…
sdk: tighten `ReadableSpan.attributes` to non-Optional `Mapping` (ope…