Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.53k stars 2.76k forks source link

Python typing error in azure-synapse-artifacts APIs #30793

Open neerajanil opened 1 year ago

neerajanil commented 1 year ago

Describe the bug Any parameter which has been described as an object in the swagger API gets set to JSON type in the sdk by the auto code-gen. This results in a type error if the parameter is passed as a string. Parameters of object type should not throw a type error for string, bool, int etc.

To Reproduce Steps to reproduce the behavior:

  1. Run the following code through a python type checker (vscode-pylance, pyright or mypy)
    
    from azure.synapse.artifacts import models

trigger = models.CustomEventsTrigger( events=["JobSuccess"], # This line throws as error in vscode when using pylance/pyright even though it works at runtime scope="dummy-scope", subject_begins_with="dummy-subject" )


**Expected behavior**
Parameters of type `object` in swagger docs should not cause python type error for inputs of python type `string`, `int`, `bool` etc. During run time passing a `string` works as expected in the above example, so type checking should also show no errors.

**Screenshots**
![image](https://github.com/Azure/azure-sdk-for-python/assets/19595225/87f0a4eb-3d61-433f-b18c-25592ed34b69)

**Additional context**
`JSON` type has been defined as follows ([link](https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models_py3.py)):
```python
JSON = MutableMapping[str, Any]

Ideally any parameter which is defined in swagger as object should have its type set to something like Union[Any, JSON] and not JSON

mccoyp commented 1 year ago

Hi @neerajanil, thank you for opening an issue! I'll tag someone who should be able to help; we'll get back to you as soon as possible.

xiangyan99 commented 1 year ago

@iscai-msft how do you think?

neerajanil commented 7 months ago

@xiangyan99 @iscai-msft Any updates on this issue?