Skip to content

[configparser] Fix return type of RawConfigParser.read#15551

Merged
srittau merged 6 commits intopython:mainfrom
LeonDeKunlun:main
Mar 26, 2026
Merged

[configparser] Fix return type of RawConfigParser.read#15551
srittau merged 6 commits intopython:mainfrom
LeonDeKunlun:main

Conversation

@LeonDeKunlun
Copy link
Contributor

No description provided.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use overloads here instead of returning a hard-to-handle list[str | bytes] type indiscriminately.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/cmdline.py:46:5: error: Signature of "read" incompatible with supertype "configparser.RawConfigParser"  [override]
+ mesonbuild/cmdline.py:46:5: note:      Superclass:
+ mesonbuild/cmdline.py:46:5: note:          @overload
+ mesonbuild/cmdline.py:46:5: note:          def [AnyStr: (str, bytes)] read(self, filenames: AnyStr | PathLike[AnyStr], encoding: str = ...) -> list[AnyStr]
+ mesonbuild/cmdline.py:46:5: note:          @overload
+ mesonbuild/cmdline.py:46:5: note:          def read(self, filenames: Iterable[str | PathLike[str]], encoding: str | None = ...) -> list[str]
+ mesonbuild/cmdline.py:46:5: note:          @overload
+ mesonbuild/cmdline.py:46:5: note:          def read(self, filenames: Iterable[bytes | PathLike[bytes]], encoding: str | None = ...) -> list[bytes]
+ mesonbuild/cmdline.py:46:5: note:          @overload
+ mesonbuild/cmdline.py:46:5: note:          def read(self, filenames: Iterable[str | bytes | PathLike[str] | PathLike[bytes]], encoding: str | None = ...) -> list[str | bytes]
+ mesonbuild/cmdline.py:46:5: note:      Subclass:
+ mesonbuild/cmdline.py:46:5: note:          def read(self, filenames: str | bytes | PathLike[str] | PathLike[bytes] | Iterable[str | bytes | PathLike[str] | PathLike[bytes]], encoding: str | None = ...) -> list[str]
+ mesonbuild/cmdline.py:47:29: error: Argument 1 to "read" of "RawConfigParser" has incompatible type "str | bytes | PathLike[str] | PathLike[bytes] | Iterable[str | bytes | PathLike[str] | PathLike[bytes]]"; expected "str | PathLike[str]"  [arg-type]

@LeonDeKunlun LeonDeKunlun requested a review from srittau March 25, 2026 12:31
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 4578526 into python:main Mar 26, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants