Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.87k stars 1.85k forks source link

pyright complains about type hints in azure speech SDK #2539

Closed msehnout closed 1 week ago

msehnout commented 2 months ago

Describe the bug

pyright, the static type checker from Microsoft, complains about the default values in speech SDK methods, consider this as an example:

class AudioOutputConfig():
    """
    ...
    """

    def __init__(self, use_default_speaker: bool = False, filename: str = None,
                 stream: AudioOutputStream = None, device_name: str = None):

The type hints are incorrect because they assume all objects are implicitly nullable which is where pyright disagrees:

error: Argument of type "None" cannot be assigned to parameter "stream" of type "AudioOutputStream" in function "__init__"
    "None" is incompatible with "AudioOutputStream" (reportArgumentType)

Speech SDK should use correct type hints with explicit nullability like this:

def __init__(self, use_default_speaker: bool = False, filename: str | None = None,
                 stream: AudioOutputStream | None = None, device_name: str | None = None):
yulin-li commented 2 months ago

Thanks for reporting this issue, we will fix it

github-actions[bot] commented 1 month ago

This item has been open without activity for 19 days. Provide a comment on status and remove "update needed" label.

pankopon commented 1 week ago

Fixed in the Speech SDK 1.41.1 release.