🐛 fix(type): stop ty flagging default_source on Action#3124
Merged
gaborbernat merged 1 commit intopypa:mainfrom Apr 15, 2026
Merged
🐛 fix(type): stop ty flagging default_source on Action#3124gaborbernat merged 1 commit intopypa:mainfrom
gaborbernat merged 1 commit intopypa:mainfrom
Conversation
ty reports unresolved-attribute on argparse.Action because default_source is attached at runtime to carry where the default came from, and the tuple-unpacking assignment made that implicit write look like a static attribute access. Split the assignment and write the dynamic field through vars(action) so the instance dict is populated directly. The resulting %(default_source)s lookup in HelpFormatter still works, and no suppression or ignore comment is needed.
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.
Running
tyonmainfails withunresolved-attributeonaction.default_sourceinsrc/virtualenv/config/cli/parser.py. The parser attachesdefault_sourcetoargparse.Actioninstances at runtime so the help formatter can render where a default came from, and the tuple-unpacking assignment was making that implicit write look like a static attribute access to the checker.The assignment is split so
action.defaultkeeps its regular attribute write, and the dynamic field is stored throughvars(action), which populates the instance__dict__directly. 🛠HelpFormatter._get_help_stringstill findsdefault_sourcevia its%(default_source)sinterpolation because argparse resolves that format spec againstvars(action).Behavior is unchanged; only the write path for the dynamic attribute differs, which lets the type checker pass without a suppression or
# ty: ignorecomment.