Fix: invoke/config.py:163 DataProxy.__setitem__ was typed as (self, key:... - #1081
Open
M001N wants to merge 1 commit into
Open
Fix: invoke/config.py:163 DataProxy.__setitem__ was typed as (self, key:...#1081M001N wants to merge 1 commit into
M001N wants to merge 1 commit into
Conversation
DataProxy.__setitem__ was typed (key: str, value: str) -> None, but Config values are commonly non-str (bool, int, dict, etc), matching __getitem__ Any return type and actual usage. Change value: str to value: Any. Adds check_type_fix.py, a standalone mypy-based check (not pytest, since tests/conftest.py imports the Unix-only termios module) that reproduces the issue and bypasses this repo's own disable_error_code assignment suppression.
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
Changed
value: strtovalue: Anyin DataProxy.setitem (invoke/config.py:163); Any was already imported from typing in that module. Pure type-annotation change, zero runtime behavior change.Problem
pyinvoke/invoke issue reference: #1064 - Type hints of config do not accept other values than str
Root Cause
invoke/config.py:163 DataProxy.setitem was typed as (self, key: str, value: str) -> None, overly narrow since Config values are commonly non-str (bool, int, dict, etc.), matching getitem's Any return type and real runtime usage. This makes mypy flag valid downstream code as an [assignment] error, but only for consumers of invoke who don't have invoke's own disable_error_code=["assignment"] suppression in their mypy config.
Testing
PASS - check_type_fix.py exits 0 (mypy reports no [assignment] error) with the fix applied; empirically verified it exits 1 with 3 [assignment] errors when reverted to the original
value: strannotation.Related Issue
#1064 - Type hints of config do not accept other values than str