Skip to content

fix(ast_utils): use field.type and field.name in prune function - #181

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/ast-utils-prune-field-type-and-name
Open

fix(ast_utils): use field.type and field.name in prune function#181
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:fix/ast-utils-prune-field-type-and-name

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Two bugs in the prune function body:

  1. is_optional(field)field is a dataclasses.Field object, but is_optional expects a type indicator (e.g. Optional[str]). Pass field.type instead.
  2. setattr(node, field, None)field is again the Field object, not a string attribute name. Pass field.name instead.

Both would raise a TypeError or AttributeError at runtime whenever prune was called on a node that matched the given field values.

Two bugs in the `prune` function:
1. `is_optional(field)` passes the `dataclasses.Field` object instead
   of its type hint; should be `is_optional(field.type)`.
2. `setattr(node, field, None)` passes the `Field` object as the
   attribute name instead of the string name; should be
   `setattr(node, field.name, None)`.

Both would raise a `TypeError` / `AttributeError` whenever `prune` was
called on a matching node.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants