Skip to content

Skip dir() names that raise AttributeError when gathering visitors - #1460

Open
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/skip-inaccessible-attrs-in-visitor-gather
Open

Skip dir() names that raise AttributeError when gathering visitors#1460
Sanjays2402 wants to merge 1 commit into
Instagram:mainfrom
Sanjays2402:fix/skip-inaccessible-attrs-in-visitor-gather

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #1458

Summary

_gather_matchers and the two _gather_constructed_*_funcs helpers iterate over dir(obj) and getattr every name. A name reported by dir() isn't guaranteed to be retrievable — zope.interface installs a __provides__ descriptor that raises AttributeError on access — so merely importing Twisted made every MatcherDecoratableVisitor/Transformer constructor crash with AttributeError: __provides__. Such names can't be visit/leave methods, so they're now fetched through a _safe_getattr helper and skipped.

Test Plan

New test_inaccessible_attribute_is_skipped in libcst/matchers/tests/test_visitors.py uses a descriptor that raises AttributeError on access; it fails with the reported AttributeError: __provides__ without the fix and passes with it. libcst/matchers/tests/ + test_add_imports.py = 180 passed; black and flake8 clean on the changed files.

_gather_matchers, _gather_constructed_visit_funcs and
_gather_constructed_leave_funcs iterate over dir(obj) and getattr each
name. A name reported by dir() is not guaranteed to be retrievable:
zope.interface installs a __provides__ descriptor that raises
AttributeError on access, so merely importing Twisted made every
MatcherDecoratableVisitor/Transformer constructor crash with
AttributeError: __provides__.

Such names cannot be visit/leave methods, so fetch them through a
_safe_getattr helper and skip them instead of propagating the error.

Fixes Instagram#1458
@meta-cla

meta-cla Bot commented Jul 25, 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.

MatcherDecoratableTransformer raises AttributeError: __provides__ for __provides__ from Twisted/zope.interface

1 participant