Skip to content

Add Resolver.get() option to retrieve node with name "." #269

@whitews

Description

@whitews

Hi @c0fec0de,

I've run into a case where a user named a node "." and the Resolver fails to retrieve the node, instead returning its parent node. Here's a MWE:

from anytree import Node, Resolver

# Create a tree structure
root = Node("root")
a1 = Node("a1", parent=root)
dot = Node(".", parent=a1)

# Create a resolver
resolver = Resolver('name')

# This finds the parent instead of the dot node
print(resolver.get(root, "/root/a1/."))

Would you be open to adding an option to the Resolver.get() method to disable pattern matching?

I'm thinking something like:

resolver.get(root, "/root/a1/.", strict=True)

to disable pattern matching. Not married to the strict name, just using it as an example. The default kwarg value could be False to ensure backwards compatibility. If you'd be amenable to something like this, I could put together a PR.

Alternatively, if there is a workaround for retrieving nodes in cases like this please let me know. I'd be open to using that method.

Appreciate your time,
Scott

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions