microsoft / kiota-abstractions-python

Abstractions library for Kiota generated Python clients
https://aka.ms/kiota/docs
MIT License
13 stars 8 forks source link

Inconsistent typing used in generated code and the libraries. #333

Open andrueastman opened 2 weeks ago

andrueastman commented 2 weeks ago

Related to https://github.com/microsoft/kiota-abstractions-python/pull/331

Running typechecking validation using generated SDK by Kiota yields errors due to the inconsistencies .

1. Usage of the ParsableFactory

The functions below use the type as a parameter

However, on generation, the parameters passed are not instances of the factory but type(class) definitions.

The relevant implementations also happen to call the create_from_discriminator_value statically directly. https://github.com/microsoft/kiota-serialization-json-python/blob/160d8a6d54237f96205f9972acbf17da5d80b2cd/kiota_serialization_json/json_parse_node.py#L215C18-L215C25

Resolving the typing inconsistency will need both generation and library changes as if we update the ParsableFactory to be a type variable as it is used and rename the current ParsableFactory we may end up breaking library functionalities calling methods like create_from_discriminator_value directly.

We probably need to either

2. Return type of request executors should be optional in the case of returning streams/bytes Taking a look at an example at https://github.com/microsoftgraph/msgraph-sdk-python/blob/416fccc20bd90a8f8d71ef7cc7519d2f63f488f5/msgraph/generated/applications/item/logo/logo_request_builder.py#L49

The function ends up returning the result of send_primitive_async which is an optional not just bytes

andrueastman commented 5 days ago

Also related to https://github.com/microsoftgraph/msgraph-sdk-python/discussions/851