Skip to content

🐛 fix(type): stop ty flagging default_source on Action#3124

Merged
gaborbernat merged 1 commit intopypa:mainfrom
gaborbernat:fix/ty-default-source
Apr 15, 2026
Merged

🐛 fix(type): stop ty flagging default_source on Action#3124
gaborbernat merged 1 commit intopypa:mainfrom
gaborbernat:fix/ty-default-source

Conversation

@gaborbernat
Copy link
Copy Markdown
Contributor

Running ty on main fails with unresolved-attribute on action.default_source in src/virtualenv/config/cli/parser.py. The parser attaches default_source to argparse.Action instances 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.default keeps its regular attribute write, and the dynamic field is stored through vars(action), which populates the instance __dict__ directly. 🛠 HelpFormatter._get_help_string still finds default_source via its %(default_source)s interpolation because argparse resolves that format spec against vars(action).

Behavior is unchanged; only the write path for the dynamic attribute differs, which lets the type checker pass without a suppression or # ty: ignore comment.

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.
@pypa pypa deleted a comment from azure-pipelines bot Apr 15, 2026
@gaborbernat gaborbernat merged commit d42ea5c into pypa:main Apr 15, 2026
113 of 114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant