Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete representation graph implementation #841

Open
colltoaction opened this issue Jan 12, 2025 · 0 comments
Open

Complete representation graph implementation #841

colltoaction opened this issue Jan 12, 2025 · 0 comments

Comments

@colltoaction
Copy link

Hi everyone!

I want to propose the use of an explicit incidence structure separate from the Node objects. The current implementation of the Representation Graph uses lists of children in each collection node. I propose to introduce a data structure that holds all incidences in one place, closer to the spec, something like:

class NodeGraph:
    def __init__(self):
        self.incidences = {}
        # ...
        self.anchors = {}
        self.aliases = {}

    def add_to_node(self, node, other):
        self.incidences[node].append(other)

    def add_node(self, node):
        self.incidences[node] = []

    def get_incidences(self, node):
        return self.incidences[node]

It is simple but not straightforward to do this refactoring because uses of the graph are spread over many modules (composer, representer, ...) and difficults the implementation of features such as anchors and recursive objects. This proposal will lead to improved code in general, such as avoiding creating and cleaning up state between calls to dumper and loader instances, and pave the way to feature completeness.

@Thom1729 I would appreciate your comments on this matter. I can work on a PR any time. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant