Skip to content

Update configparser.SectionProxy.get* to return T | None when fallback is not specified #12936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

brianschubert
Copy link
Contributor

@brianschubert brianschubert commented Oct 31, 2024

Closes #12933

All SectionProxy.get* methods return None when the key isn't found and a fallback isn't specified.

Since None being returned is both likely and semantically meaningful, I think returning a union and forcing callers to handle the None case makes sense here.

This comment has been minimized.

@brianschubert
Copy link
Contributor Author

mypy_primer hits look good:

  • porcupine: uses .get("root", "false"). This will go away with #12935.
  • nox: first hit uses .get("set_env", ""), which will go away with #12935. Second hit uses .get("change_dir"), which is a true hit.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

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

nox (https://github.com/wntrblm/nox)
+ nox/tox_to_nox.py:128: error: Argument 1 to "Path" has incompatible type "Optional[str]"; expected "Union[str, PathLike[str]]"  [arg-type]

@brianschubert brianschubert marked this pull request as ready for review November 25, 2024 17:10
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.

LGTM, thanks!

@srittau srittau merged commit b15c302 into python:main Nov 25, 2024
63 checks passed
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this pull request Jan 6, 2025
mypy does not do type narrowing with "in":
python/mypy#12535

And mypy now knows that those values can be None:
python/typeshed#12936
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.

configparser.SectionProxy.get* may return None
2 participants