Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests with Python 3.14 and hypothesmith/libcst ends with: AttributeError: 'int' object has no attribute '_codegen' #1302

Open
befeleme opened this issue Mar 7, 2025 · 2 comments

Comments

@befeleme
Copy link

befeleme commented Mar 7, 2025

When trying to build mccabe with Python 3.14, the test generating code using hypothesmith and libcst fails.
I don't see anything specific to mccabe in the test itself (https://github.com/PyCQA/mccabe/blob/master/test_mccabe.py#L244), the fail comes from max_example.

Here's the traceback.

=================================== FAILURES ===================================
________________ test_idempotent_any_syntatically_valid_python _________________

    @settings(
>       max_examples=1000,  # roughly 1k tests/minute, or half that under coverage
        derandomize=False,  # deterministic mode to avoid CI flakiness
        deadline=None,  # ignore Hypothesis' health checks; we already know that
        suppress_health_check=HealthCheck.all(),  # this is slow and filter-heavy.
    )

test_mccabe.py:245: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.14/site-packages/hypothesmith/cst.py:278: in <lambda>
    code = st.from_type(node).map(lambda n: libcst.Module([n]).code).filter(compilable)
/usr/lib64/python3.14/site-packages/libcst/_nodes/module.py:116: in code
    return self.code_for_node(self)
/usr/lib64/python3.14/site-packages/libcst/_nodes/module.py:136: in code_for_node
    node._codegen(state)
/usr/lib64/python3.14/site-packages/libcst/_nodes/base.py:299: in _codegen
    self._codegen_impl(state, **kwargs)
/usr/lib64/python3.14/site-packages/libcst/_nodes/module.py:99: in _codegen_impl
    stmt._codegen(state)
/usr/lib64/python3.14/site-packages/libcst/_nodes/base.py:299: in _codegen
    self._codegen_impl(state, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Module(
    body=[
        0,
    ],
    header=[],
    footer=[],
    encoding='utf-8',
    default_indent='    ',
    default_newline='\n',
    has_trailing_newline=True,
)
state = CodegenState(default_indent='    ', default_newline='\n', provider=None, indent_tokens=[], tokens=[])

    def _codegen_impl(self, state: CodegenState) -> None:
        for h in self.header:
            h._codegen(state)
        for stmt in self.body:
>           stmt._codegen(state)
E           AttributeError: 'int' object has no attribute '_codegen'
E           while generating 'src_contents' from one_of(<hypothesmith.syntactic.GrammarStrategy object at 0x7f85519c0d70>, builds_filtering(Module).map(lambda n: libcst.Module([n]).code).filter(compilable).map(record_targets))
E           Explanation:
E               These lines were always and only run by failing examples:
E                   /usr/lib/python3.14/site-packages/hypothesmith/cst.py:122
E           Highest target scores:
E                          1  (label='(hypothesmith from_node) number of unique ast node types')
E                          1  (label='(hypothesmith from_node) total number of ast nodes')
E                          1  (label='(hypothesmith) number of unique ast node types')
E                          1  (label='(hypothesmith) total number of ast nodes')
E                          3  (label='(hypothesmith from_node) instructions in bytecode')
E                          3  (label='(hypothesmith) instructions in bytecode')

/usr/lib64/python3.14/site-packages/libcst/_nodes/module.py:99: AttributeError
@zsol
Copy link
Member

zsol commented Mar 7, 2025

Can you repro this with 3.13? The test output says there's a module with body=[0] which is not a valid cst

@befeleme
Copy link
Author

befeleme commented Mar 7, 2025

The test passes alright with Python 3.13 (in both cases it's hypothesmith 0.3.3, LibCST 1.6.0)

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

No branches or pull requests

2 participants