Azure / Azure/azure-sdk-for-python

Inline typing for Requests

Open
#46,705 0 comments 1 reaction 1 assignee Claimed by @kashifkhan View on GitHub
Azure.Core
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

- **Package Name**: azure-core
- **Package Version**: 1.40.0
- **Operating System**: All
- **Python Version**: All

**Describe the bug**
Starting with Requests 2.34.0, typing will be moving from Typeshed to inline types for Requests. Those are largely the same except for some technical corrections, and more complete compound types.

We've been testing downstream projects and most are passing with our pre-release ([2.34.0.dev1](https://pypi.org/project/requests/2.34.0.dev1/)). We're seeing two issues with pyright in the Azure SDK for Python though.

* [sdk/core/corehttp/corehttp/transport/requests/_requests_basic.py#L131-L138](https://github.com/Azure/azure-sdk-for-python/blob/1c4e2bf55a7e9cce381897fed6ed2e8a00f8afe3/sdk/core/corehttp/corehttp/transport/requests/_requests_basic.py#L131-L138)
* [sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py#L322-L356](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py#L322-L356)

Both of these `send` implementations type `proxies` as `MutableMapping[str, str]`. While that matches Typeshed, `.copy()` will be called on input for the proxies parameter. The `MutableMapping` interface doesn't require this, which can lead to runtime failures. The parameter should be typed as `dict[str, str]` to reflect the actual API contract.

**To Reproduce**
Steps to reproduce the behavior:
1. Install the pre-release of Requests (2.34.0.dev1).
2. Run type checking as usual.

**Expected behavior**
The type checkers pass with valid types.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.