Repository navigation
Fix custom scheme config type narrowing - #384
Merged
Merged
Conversation
kuenishi
approved these changes
Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NonetoConfigParserBackground
mypy 2.0 enabled
--local-partial-typesby default. This option changes type inference when a module-level variable is initialized in another scope.1PFIO initializes
_configtoNoneat module scope and assigns aConfigParserfrom_load_config(). The mypy migration notes use the same pattern—a module variable initialized toNoneand assigned throughglobalin another function—and specify that the inferred type remains optional.2A call to
_load_config()therefore does not narrow_configin the caller. The assertions make the existing runtime invariant explicit to the type checker.Testing
python3 -m py_compile pfio/v2/config.pygit diff --checkFootnotes
mypy, “Enable
--local-partial-typesby Default,” Mypy Release Notes: https://mypy.readthedocs.io/en/stable/changelog.html#enable-local-partial-types-by-default ↩mypy, “Improved Compatibility for Local Partial Types,” Mypy Release Notes: https://mypy.readthedocs.io/en/stable/changelog.html#improved-compatibility-for-local-partial-types ↩