Skip to content

No optional type hinting on some optional constructor args #4454

@DominicOram

Description

@DominicOram

Describe your environment

OS: RHEL 8
Python version: 3.11
SDK version: 1.30.0
API version: 1.30.0

What happened?

The latest version of pyright is stricter and raises errors if a constructor argument is not typed as optional and a caller does not provide it.

Steps to Reproduce

Run the latest pyright against something like:

    traceProvider = TracerProvider(resource=resource)
    processor = BatchSpanProcessor(
        OTLPSpanExporter(endpoint="http://0.0.0.0:4318/v1/traces")
    )
    traceProvider.add_span_processor(processor)
    trace.set_tracer_provider(traceProvider)

    reader = PeriodicExportingMetricReader(
        OTLPMetricExporter(endpoint="http://0.0.0.0:4318/v1/metrics")
    )

and see errors like:

 - error: Argument of type "None" cannot be assigned to parameter "max_queue_size" of type "int" in function "__init__"
    "None" is not assignable to "int" (reportArgumentType)
- error: Argument of type "None" cannot be assigned to parameter "schedule_delay_millis" of type "float" in function "__init__"
    "None" is not assignable to "float" (reportArgumentType)
- error: Argument of type "None" cannot be assigned to parameter "max_export_batch_size" of type "int" in function "__init__"
    "None" is not assignable to "int" (reportArgumentType)
- error: Argument of type "None" cannot be assigned to parameter "export_timeout_millis" of type "float" in function "__init__"
    "None" is not assignable to "float" (reportArgumentType)
- error: Argument of type "None" cannot be assigned to parameter "preferred_temporality" of type "Dict[type, AggregationTemporality]" in function "__init__"
    "None" is not assignable to "Dict[type, AggregationTemporality]" (reportArgumentType)
- error: Argument of type "None" cannot be assigned to parameter "preferred_aggregation" of type "Dict[type, Aggregation]" in function "__init__"
    "None" is not assignable to "Dict[type, Aggregation]" (reportArgumentType)
6 errors, 0 warnings, 0 informations 

Expected Result

No pyright errors on the above snippet

Actual Result

The above errors

Additional context

No response

Would you like to implement a fix?

Yes

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