#๐Ÿ”’ multimethod package and visitor pattern for multiple dispatch

15 messages ยท Page 1 of 1 (latest)

thorn mothBOT
#

@uneven escarp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

uneven escarp
#

Hmm I can't see the original question, I might have done something wrong in my original post. It just says Original message was deleted. Did I do something wrong?

vapid field
#

Did you try to post a file or a lot of text?

#

If you were trying to post your program try using the paste service

#

!paste

thorn mothBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

clear tiger
#

It was the attachment that got the message zapped

#

Here is your original:

I'm working on a refactor in a code base. I'm implementing the visitor pattern for traversing a tree data structure. My current implementation uses match and case syntax. That doesn't allow for inheritance very well. I thought to replace my implementation with the multimethod package, but have run into a problem I'm not sure how to resolve.

I have created a minimum example of the problem in github.
https://github.com/FuerteTurtle/multi_method_visitor
The code is also linked as a file.

There is a potential solution commented out in the code, but it is unsatisfying because my specific trees I'm traversing have many different Node types and I don't want to explicitly call super() behavior for ever single node type.

Please note to run the code example you will need to install the multimethod package. match case syntax was introduced in python 3.10 I believe so you will need to be on 3.10 or greater

uneven escarp
clear tiger
#

We cannot verify files attached, so we prefer people to use the pastebin to share code

#

The attachment section is a discord thing

uneven escarp
#

I'm going to close and reopen using the paste functionality instead. If someone is kind enough to help I wouldn't want them to have to read a whole thread showing how I asked the question wrong in discord.

clear tiger
#

No worries

thorn mothBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ multimethod package and visitor pattern for multiple dispatch