Skip to content

Fix custom scheme config type narrowing - #384

Merged
kuenishi merged 1 commit into
masterfrom
fix/custom-scheme-config-mypy
Oct 5, 2026
Merged

kuenishi merged 1 commit into
masterfrom
fix/custom-scheme-config-mypy

Conversation

@k5342

@k5342 k5342 commented Oct 2, 2026

Copy link
Copy Markdown
Member

Summary

  • assert that the lazily loaded custom scheme configuration is initialized
  • allow mypy to narrow the global configuration from None to ConfigParser

Background

mypy 2.0 enabled --local-partial-types by default. This option changes type inference when a module-level variable is initialized in another scope.1

PFIO initializes _config to None at module scope and assigns a ConfigParser from _load_config(). The mypy migration notes use the same pattern—a module variable initialized to None and assigned through global in another function—and specify that the inferred type remains optional.2

A call to _load_config() therefore does not narrow _config in the caller. The assertions make the existing runtime invariant explicit to the type checker.

Testing

  • python3 -m py_compile pfio/v2/config.py
  • git diff --check

Footnotes

  1. mypy, “Enable --local-partial-types by Default,” Mypy Release Notes: https://mypy.readthedocs.io/en/stable/changelog.html#enable-local-partial-types-by-default ↩

  2. mypy, “Improved Compatibility for Local Partial Types,” Mypy Release Notes: https://mypy.readthedocs.io/en/stable/changelog.html#improved-compatibility-for-local-partial-types ↩

@kuenishi kuenishi modified the milestones: 2.10, 2.11 Oct 2, 2026
@kuenishi
kuenishi merged commit 811a07c into master Oct 5, 2026
12 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