MatcherDecoratableTransformer raises AttributeError: __provides__ for __provides__ from Twisted/zope.interface
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 229
- PR merge metrics
- No merged PRs in 30d
Description
A short reproducible example:
```python
import twisted.internet.base
from libcst.codemod import CodemodContext
from libcst.codemod.visitors import AddImportsVisitor, ImportItem
AddImportsVisitor(CodemodContext(), [ImportItem("os")])
```
This crashes:
```
Traceback (most recent call last):
File "", line 1, in
AddImportsVisitor(CodemodContext(), [ImportItem("os", "path", None)])
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".env/lib/python3.13/site-packages/libcst/codemod/visitors/_add_imports.py", line 151, in __init__
super().__init__(context)
~~~~~~~~~~~~~~~~^^^^^^^^^
File ".env/lib/python3.13/site-packages/libcst/codemod/_visitor.py", line 29, in __init__
MatcherDecoratableTransformer.__init__(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File ".env/lib/python3.13/site-packages/libcst/matchers/_visitors.py", line 456, in __init__
] = _gather_constructed_visit_funcs(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File ".env/lib/python3.13/site-packages/libcst/matchers/_visitors.py", line 314, in _gather_constructed_visit_funcs
possible_func = getattr(obj, funcname)
AttributeError: __provides__
```
There is various magic in Twisted/zope.interface that leads to some inconsistency about `abc.ABC`, `__provides__` and descriptors that I can't wrap my head around which evidently leads to `_gather_constructed_visit_funcs()` seeing `'__provides__'` in `dir(obj)` but not being able to access it (direct `hasattr()` there also returns `False`).
```
libcst==1.8.6
Twisted==26.4.0
zope.interface==8.5
```
```pycon
>>> '__provides__' in dir(AddImportsVisitor)
True
>>> hasattr(AddImportsVisitor, '__provides__')
False
>>> import abc
>>> hasattr(abc.ABC, '__provides__')
True
>>> issubclass(AddImportsVisitor, abc.ABC)
True
```
Contributor guide
Research direction
Reproduce the example with the listed LibCST, Twisted, and zope.interface versions, then inspect libcst/matchers/_visitors.py at _gather_constructed_visit_funcs() and the MatcherDecoratableTransformer initializer. Trace why __provides__ appears in dir() but cannot be accessed, and add a regression check showing that constructing AddImportsVisitor no longer raises AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100