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

Crash in modulo expression #1700

Closed
jacobtylerwalls opened this issue Jul 10, 2022 · 3 comments · Fixed by #1701
Closed

Crash in modulo expression #1700

jacobtylerwalls opened this issue Jul 10, 2022 · 3 comments · Fixed by #1701

Comments

@jacobtylerwalls
Copy link
Member

Steps to reproduce

class BatchSequence:
    def __init__(self):
        self.batch_size = 0

    def __len__(self):
        return 20 % self.batch_size

Current behavior

  File "/Users/.../astroid/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/Users/.../astroid/astroid/inference.py", line 480, in _filter_operation_errors
    for result in infer_callable(self, context):
  File "/Users/.../astroid/astroid/inference.py", line 817, in _infer_binop
    yield from _infer_binary_operation(lhs, rhs, self, context, _get_binop_flow)
  File "/Users/.../astroid/astroid/inference.py", line 768, in _infer_binary_operation
    results = list(method())
  File "/Users/.../astroid/astroid/inference.py", line 607, in _invoke_binop_inference
    return iter(_infer_old_style_string_formatting(instance, other, context))
  File "/Users/.../astroid/astroid/inference.py", line 594, in _infer_old_style_string_formatting
    return (nodes.const_factory(instance.value % values),)
ZeroDivisionError: integer division or modulo by zero

Expected behavior

Regression in 957d3d6
Found in pylint primer (the old primer with keras, so I didn't see it yesterday when it was blocked on stdlib failures)
@DanielNoord would you be able to take a look for 2.12.2?

@jacobtylerwalls jacobtylerwalls added this to the 2.12.2 milestone Jul 10, 2022
@jacobtylerwalls
Copy link
Member Author

Ah, I see how simple this is. I'm online, so I can get to it.

@DanielNoord
Copy link
Collaborator

I'll create a fix!

@jacobtylerwalls
Copy link
Member Author

Go for it!

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

Successfully merging a pull request may close this issue.

2 participants