Skip to content

feat: define default visit method for visitor#188

Open
bolajiwahab wants to merge 2 commits into
lelit:v7from
bolajiwahab:feat__define-default-visit-method
Open

feat: define default visit method for visitor#188
bolajiwahab wants to merge 2 commits into
lelit:v7from
bolajiwahab:feat__define-default-visit-method

Conversation

@bolajiwahab
Copy link
Copy Markdown
Contributor

@bolajiwahab bolajiwahab commented May 10, 2026

Description

This change fixes the typing inconsistency in the visitor base class by replacing the dynamically assigned visit = None attribute with a properly defined method signature.

Previously, the base class exposed visit as an attribute:

visit = None

while subclasses can either choose to implement/override it as a concrete method:

def visit(self, ancestors: visitors.Ancestor, node: ast.Node) -> None:

This then creates a divergence between the superclass and subclass definitions:

  • superclass treats visit as an optional attribute/callback
  • subclasses treated visit as an actual overridable method

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:

Signature of "visit" incompatible with supertype "Visitor"  [override]

because the superclass did not define a real method signature to override.

This PR resolves the issue by defining visit() as an explicit no-op method in the base class, establishing a consistent and type-safe inheritance contract for subclasses.

Comment thread pglast/visitors.py Outdated
def visit(self, ancestors, node):
"""
The default *visit* method for any node without a specific one.
When ``None``, nothing happens.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, please remove this last sentence from the docstring, and check the call site to remove the is None protection.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v7@21cc4b6). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bolajiwahab bolajiwahab requested a review from lelit May 10, 2026 16:48
@bolajiwahab bolajiwahab marked this pull request as ready for review May 10, 2026 16:59
@lelit
Copy link
Copy Markdown
Owner

lelit commented May 11, 2026

Thank you, and sorry for being so fussy. I can take care of these last minutiae myself.

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

Successfully merging this pull request may close these issues.

3 participants