Skip to content

Possible 4.1.2 regression: AttributeError: 'BinOp' object has no attribute 'left' #384

@schmidt-ai

Description

@schmidt-ai

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.1.2

Python version

3.10.12

What happened?

When running pytest on my codebase with the typeguard plugin enabled, I get the following stack trace:

venv/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
venv/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
venv/lib/python3.10/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
venv/lib/python3.10/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
venv/lib/python3.10/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
venv/lib/python3.10/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
venv/lib/python3.10/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
venv/lib/python3.10/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
../../.pyenv/versions/3.10.11/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/datapipe_test.py:7: in <module>
    from src.datapipe import Mask, TMACoreCropDataset
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
venv/lib/python3.10/site-packages/typeguard/_importhook.py:98: in exec_module
    super().exec_module(module)
<frozen importlib._bootstrap_external>:879: in exec_module
    ???
<frozen importlib._bootstrap_external>:1017: in get_code
    ???
venv/lib/python3.10/site-packages/typeguard/_importhook.py:75: in source_to_code
    tree = TypeguardTransformer().visit(tree)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:608: in visit_Module
    self.generic_visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:494: in generic_visit
    value = self.visit(value)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:653: in visit_ClassDef
    self.generic_visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:494: in generic_visit
    value = self.visit(value)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:733: in visit_FunctionDef
    annotation = self._convert_annotation(deepcopy(arg.annotation))
venv/lib/python3.10/site-packages/typeguard/_transformer.py:593: in _convert_annotation
    new_annotation = cast(expr, AnnotationTransformer(self).visit(annotation))
venv/lib/python3.10/site-packages/typeguard/_transformer.py:356: in visit
    new_node = super().visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:486: in visit_Constant
    new_node = self.visit(expression)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:356: in visit
    new_node = super().visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:376: in generic_visit
    return super().generic_visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:503: in generic_visit
    new_node = self.visit(old_value)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:356: in visit
    new_node = super().visit(node)
../../.pyenv/versions/3.10.11/lib/python3.10/ast.py:418: in visit
    return visitor(node)
venv/lib/python3.10/site-packages/typeguard/_transformer.py:383: in visit_BinOp
    if self._memo.name_matches(node.left, *anytype_names):
E   AttributeError: 'BinOp' object has no attribute 'left'

How can we reproduce the bug?

I suspect this may be an edge case interaction with pandas. I will try to confirm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions