Skip to content

semconv: Usage of Final annotation for Enum attributes is an error #4083

@yangskyboxlabs

Description

@yangskyboxlabs

Describe your environment

opentelemetry-semantic-conventions==0.47b0

What happened?

#3966 added many Final annotations to semantic convention literals.

However, usage of any annotation for Enum member attributes is considered invalid, and a bare Final not being flagged appear to be an edge case that was overlooked in at least pyright: microsoft/pyright#8543 (comment)

This leads to misleading type checker errors.

Steps to Reproduce

Consider:

from opentelemetry.semconv.attributes.otel_attributes import OtelStatusCodeValues

def get_ok() -> OtelStatusCodeValues:
    return OtelStatusCodeValues.OK

Expected Result

No type violations in get_ok().

Actual Result

Expression of type "Literal['OK']" is incompatible with return type "OtelStatusCodeValues"
  "Literal['OK']" is incompatible with "OtelStatusCodeValues"Pylance[reportReturnType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportReturnType)

Additional context

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions