feat: define default visit method for visitor#188
Open
bolajiwahab wants to merge 2 commits into
Open
Conversation
lelit
reviewed
May 10, 2026
| def visit(self, ancestors, node): | ||
| """ | ||
| The default *visit* method for any node without a specific one. | ||
| When ``None``, nothing happens. |
Owner
There was a problem hiding this comment.
Ok, please remove this last sentence from the docstring, and check the call site to remove the is None protection.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v7 #188 +/- ##
=====================================
Coverage ? 99.54%
=====================================
Files ? 22
Lines ? 7253
Branches ? 0
=====================================
Hits ? 7220
Misses ? 33
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
|
Thank you, and sorry for being so fussy. I can take care of these last minutiae myself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change fixes the typing inconsistency in the visitor base class by replacing the dynamically assigned
visit = Noneattribute with a properly defined method signature.Previously, the base class exposed visit as an attribute:
while subclasses can either choose to implement/override it as a concrete method:
This then creates a divergence between the superclass and subclass definitions:
Although this worked at runtime due to Python’s dynamic nature, static type checkers such as mypy interpreted the superclass contract differently and reported errors similar to:
because the superclass did not define a real method signature to override.
This PR resolves the issue by defining
visit()as an explicitno-opmethod in the base class, establishing a consistent and type-safe inheritance contract for subclasses.