py-tree-sitter icon indicating copy to clipboard operation
py-tree-sitter copied to clipboard

node.children_by_field_name returns unnamed children for bad input

Open NorthIsUp opened this issue 3 years ago • 1 comments

expected result: node.children_by_field_name('') should return an empty list

actual result: node.children_by_field_name('') returns all unnamed children

ipdb> node.text
b'Foo: A = 1'
ipdb> node.children_by_field_name('left')
[<Node kind=identifier, start_point=(0, 0), end_point=(0, 3)>]
ipdb> node.children_by_field_name('')
[<Node kind=":", start_point=(0, 3), end_point=(0, 4)>, <Node kind="=", start_point=(0, 7), end_point=(0, 8)>]
ipdb> node.children_by_field_name(None)
*** TypeError: a bytes-like object is required, not 'NoneType'
ipdb> node.children_by_field_name('asdf')
[<Node kind=":", start_point=(0, 3), end_point=(0, 4)>, <Node kind="=", start_point=(0, 7), end_point=(0, 8)>]

NorthIsUp avatar Mar 15 '22 22:03 NorthIsUp

@maxbrunsfeld thoughts?

lunixbochs avatar Mar 31 '22 15:03 lunixbochs

I've stumbled across the same issue. I'm writing a grammar, and I'd like users to be able to do something like function_def.children_by_field_name("arg"), and have it return an empty list when there are no arguments.

wstevick avatar Dec 03 '23 12:12 wstevick

#180 Fixes this

wstevick avatar Dec 03 '23 13:12 wstevick