-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix: Make filtering children by class in traverse() actually work #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asb, thank you for the fix. I guess it was a mistake to accept the previous PR without a more complete set of tests.
If you don't mind, I have just slightly changed the PR title - can you please do the same with your commit message, while amending the commit with my little suggestion from the code review? :)
The `traverse()` utility function was previously written to filter children by class using `issubclass(child, klass):`. But the first argument to `issubclass()` must be a class so this will always raise an exception when trying to use the functionality. This patch corrects the call to `isinstance(child, klass)` and adds a test.
fc0ffe9
to
5f7e87d
Compare
@pbodnar: thanks for such a rapid review, I've made the suggested changes. It's an unfortunate bug, but the traverse utility does seem pretty handy to have in the codebase. It's nice to have a helper to make it easier to do information extraction or even light modifications at the AST level, as an alternative/companion to customising the renderer. |
@asb, thanks for the quick fix. :) |
I'm now wondering what the behaviour should be when specifying a class to filter on and also setting Given filtering by class didn't work previously, there's an opportunity to tweak this without breaking anyone's code. |
@asb, good point. I can imagine that most people would expect, like you, that filtering by class will always win over |
Sure thing - see #158 |
…se is fixed Now my fixes <miyuchina/mistletoe#157> <miyuchina/mistletoe#158> <miyuchina/mistletoe#159> are in a released version, just use the upstream traverse implementation.
…se is fixed Now my fixes <miyuchina/mistletoe#157> <miyuchina/mistletoe#158> <miyuchina/mistletoe#159> are in a released version, just use the upstream traverse implementation.
The
traverse()
utility function was previously written to filterchildren by class using
issubclass(child, klass):
. But the firstargument to
issubclass()
must be a class so this will always raise anexception when trying to use the functionality. This patch corrects the
call to
isinstance(child, klass)
and adds a test.