Skip to content

Intersphinx: resolve type-check failures in inventory loading module - #12879

Merged
AA-Turner merged 3 commits into
sphinx-doc:masterfrom
khanxmetu:issue-12864
Sep 18, 2024
Merged

AA-Turner merged 3 commits into
sphinx-doc:masterfrom
khanxmetu:issue-12864

Conversation

@khanxmetu

@khanxmetu khanxmetu commented Sep 10, 2024 •

Copy link
Copy Markdown
Contributor

Feature or Bugfix

  • Bugfix
  • Refactoring

Purpose

  • Resolve the type-check errors by defining a "file-like" readable stream protocol for inventory loading module.

Detail

  • Bug 1: Incompatible return value type (got "HTTPResponse | Any", expected "IO[Any]") [return-value]. This is due to urllib3.response.HTTPResponse returned by requests.Response().raw not conforming to io.BytesIO. Although the docs state that the object follows the file-like behavior, however due to its inheritence structure it is not possible to cast to typing.IO. Moreover following the ideas from What are `typing.IO`, `TextIO`, and `BinaryIO` good for? python/typing#829 (comment), we should avoid objects typed as typing.IO and use protocols instead. Therefore a ReadableStream protocol is created.
  • Bug 2: Cannot assign to a method [method-assign]. Assigning boolean to urllib3.response.HTTPResponse.decode_content works. Streaming gzipped responses psf/requests#2155 (comment)

Relates

Comment thread sphinx/ext/intersphinx/_load.py Resolved
@jayaddison

Copy link
Copy Markdown
Contributor

@khanxmetu please could you add an entry to the CHANGES.rst file to describe this fix?

@AA-Turner AA-Turner changed the title Closes #12864: Intersphinx: resolve type-check failures in inventory loading module Intersphinx: resolve type-check failures in inventory loading module Sep 18, 2024
@AA-Turner
AA-Turner merged commit e4e78b3 into sphinx-doc:master Sep 18, 2024
@AA-Turner

Copy link
Copy Markdown
Member

Thanks @khanxmetu!

A

@AA-Turner AA-Turner added this to the 8.1.x milestone Oct 6, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing: Intersphinx: mypy type errors in inventory loading

3 participants