Skip to content

Allow FlattenSentinel in matcher decorator return annotations - #1465

Open
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/flatten-sentinel-return-annotation
Open

Allow FlattenSentinel in matcher decorator return annotations#1465
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/flatten-sentinel-return-annotation

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #1075

Summary

Annotating a @leave-decorated method with FlattenSentinel raised TypeError: issubclass() arg 1 must be a class, even though returning a FlattenSentinel from leave_<Node> is valid.

Two causes: the generated TYPED_FUNCTION_RETURN_MAPPING omitted FlattenSentinel entirely (unlike the leave_ signatures gen_visitor_functions emits), and _get_possible_annotated_classes passed the parameterized generic FlattenSentinel[BaseStatement] straight to issubclass(), which only accepts classes. gen_type_mapping now mirrors gen_visitor_functions for sequence-valued nodes, and generic aliases are unwrapped to their origin class before the subclass check. _return_types.py is regenerated output.

Test Plan

Two tests in libcst/matchers/tests/test_visitors.py (parameterized and bare FlattenSentinel) fail on main with the reported TypeError and pass with the fix. libcst/matchers/tests 145 passed / 1 skipped; libcst/codemod unchanged from baseline; ufmt check clean on the touched files.

This change was prepared with AI assistance; the regression tests were run locally and fail without the fix.

Annotating a @leave-decorated method with FlattenSentinel raised
TypeError: issubclass() arg 1 must be a class, even though returning a
FlattenSentinel from leave_<Node> is valid.

Two causes: the generated TYPED_FUNCTION_RETURN_MAPPING omitted
FlattenSentinel entirely (unlike the leave_ signatures in
_typed_visitor.py), and _get_possible_annotated_classes passed the
parameterized generic FlattenSentinel[BaseStatement] straight to
issubclass(), which only accepts classes.

gen_type_mapping now mirrors gen_visitor_functions and emits
FlattenSentinel for sequence-valued nodes, and generic aliases are
unwrapped to their origin class before the subclass check.
@meta-cla

meta-cla Bot commented Jul 31, 2026

Copy link
Copy Markdown

Hi @Sanjays2402!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 31, 2026
@meta-cla

meta-cla Bot commented Jul 31, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FlattenSentinel can't be used as return type annotation

1 participant