To my surprise, wikicode.get_parent() does not get you the section a node is part of:
import mwparserfromhell as mwp
text = """==foo== {{Template:Foo}} """ wikicode = mwp.parse(text) print(wikicode.get_tree())
print('++++++++++')
node = wikicode.nodes[-2] print(f"{node=}") print(f"{wikicode.get_parent(node)=}")
prints:
== foo == \n {{ Template:Foo }} \n ++++++++++ node='{{Template:Foo}}' wikicode.get_parent(node)=None
Am I just doing this wrong?