Incorrect type annotation for iter_lines
The type annotation for Response.iter_lines misses that chunk_size can be None, causing valid code to fail type checks.
This seems pretty trivial to fix (e.g. https://github.com/psf/requests/compare/main...grantisu:requests:gmathews/tiny-type-fix), but I'm not able to open a PR since I'm not a collaborator on the repo.
Hi, I'd like to work on this. I'll submit a focused typing fix with regression coverage shortly.
I see the reporter already has the fix prepared on a comparison branch, so I’m stepping back to avoid duplicating that work.
I see the reporter already has the fix prepared on a comparison branch, so I’m stepping back to avoid duplicating that work.
The work was pretty minor; feel free to duplicate/copy/steal/expand/etc if it leads to a better/quicker outcome.
Hi @grantisu @nateprewitt,
Following up on this, I've prepared and verified the fix along with parameterized tests and static typing validation.
Since PR creation is restricted to collaborators on this repository, the tested changes are available on my fork here:
Branch: agustin18:requests:fix/iter-lines-chunk-size-type-7630
Compare Diff: psf/requests/compare/main...agustin18:requests:fix/iter-lines-chunk-size-type-7630
Changes
- Updated
chunk_size: int | None = ITER_CHUNK_SIZEin both@overloadsignatures and theiter_linesmethod definition insrc/requests/models.py. - Added parameterized regression tests in
tests/test_requests.pycoveringchunk_size=Noneandchunk_size=512with bothdecode_unicode=FalseandTrue. - Verified locally:
pyright src/requests/: 0 errors.- All 6
iter_linesoverload variants pass Pyright strict type check. - All 343 pytest tests pass.
- All pre-commit hooks (ruff check, ruff format, whitespace) pass cleanly.
Maintainers can pull directly from this branch or grant access to open the PR.
Put together the typing fix along with unit test coverage on a branch here if a collaborator wants to pull or cherry-pick it: https://github.com/DevMubarak1/requests/tree/fix/iter-lines-chunk-size-type (diff: https://github.com/psf/requests/compare/main...DevMubarak1:requests:fix/iter-lines-chunk-size-type)
I’m working on a focused fix for the overloads so is accepted by type checkers, with runtime behavior unchanged.