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 under very specific scenario #62

Open
An-dz opened this issue Sep 21, 2019 · 0 comments
Open

Crash under very specific scenario #62

An-dz opened this issue Sep 21, 2019 · 0 comments
Labels
bug Something isn't working new This issue hasn't been looked at yet

Comments

@An-dz
Copy link

An-dz commented Sep 21, 2019

Description

Good Smell was crashing on one of my files and I managed to reduce it to a minimal reproducible case. It crashes only if there's a for using a range that takes a len and that inside the loop it appends to a list an object that is part of a list described in a Class. Code is below.

To Reproduce

  1. Save the following file somewhere:
for i in range(len(random_a)):
    random_b.append(RandomClass.random_c[i])
  1. Run good_smell warn on the file
  2. Get error

Expected behavior

Good smell should not crash, especially when running with flake8 as it breaks all of flake8.

Desktop

  • OS: Arch Linux and Windows 8.1
  • Python version: 3.7.4
  • Version good_smell 0.13.0

Additional context

Might be related with #61

Error log:

Traceback (most recent call last):
  File "C:\Program Files\Python37\Scripts\good_smell-script.py", line 11, in <module>
    load_entry_point('good-smell==0.13.0', 'console_scripts', 'good_smell')()
  File "c:\program files\python37\lib\site-packages\good_smell\main.py", line 46, in main
    Fire({"fix": print_fixed_smell, "warn": print_smell_warnings})
  File "c:\program files\python37\lib\site-packages\fire\core.py", line 127, in Fire
    component_trace = _Fire(component, args, context, name)
  File "c:\program files\python37\lib\site-packages\fire\core.py", line 366, in _Fire
    component, remaining_args)
  File "c:\program files\python37\lib\site-packages\fire\core.py", line 542, in _CallCallable
    result = fn(*varargs, **kwargs)
  File "c:\program files\python37\lib\site-packages\good_smell\main.py", line 14, in print_smell_warnings
    for warning in smell_warnings(Path(path).read_text(), path)
  File "c:\program files\python37\lib\site-packages\good_smell\main.py", line 13, in <genexpr>
    warning.warning_string()
  File "c:\program files\python37\lib\site-packages\good_smell\main.py", line 22, in smell_warnings
    source_code=source, path=str(path)
  File "c:\program files\python37\lib\site-packages\good_smell\ast_smell.py", line 29, in check_for_smell
    transformer.visit(self.tree)
  File "c:\program files\python37\lib\site-packages\good_smell\ast_smell.py", line 20, in visit
    return self.generic_visit(node)
  File "c:\program files\python37\lib\ast.py", line 317, in generic_visit
    value = self.visit(value)
  File "c:\program files\python37\lib\site-packages\good_smell\ast_smell.py", line 22, in visit
    return super().visit(node)
  File "c:\program files\python37\lib\ast.py", line 262, in visit
    return visitor(node)
  File "c:\program files\python37\lib\site-packages\good_smell\smells\range_len_fix.py", line 57, in visit_For
    new_body = deleter.visit(node).body or [ast.Pass()]
  File "c:\program files\python37\lib\ast.py", line 262, in visit
    return visitor(node)
  File "c:\program files\python37\lib\ast.py", line 317, in generic_visit
    value = self.visit(value)
  File "c:\program files\python37\lib\ast.py", line 262, in visit
    return visitor(node)
  File "c:\program files\python37\lib\ast.py", line 326, in generic_visit
    new_node = self.visit(old_value)
  File "c:\program files\python37\lib\ast.py", line 262, in visit
    return visitor(node)
  File "c:\program files\python37\lib\ast.py", line 317, in generic_visit
    value = self.visit(value)
  File "c:\program files\python37\lib\ast.py", line 262, in visit
    return visitor(node)
  File "c:\program files\python37\lib\site-packages\good_smell\smells\range_len_fix.py", line 46, in visit_Subscript
    if self.accesses_seq(node):
  File "c:\program files\python37\lib\site-packages\good_smell\smells\range_len_fix.py", line 40, in accesses_seq
    and node.value.id == self.seq.id
AttributeError: 'Attribute' object has no attribute 'id'
@An-dz An-dz added bug Something isn't working new This issue hasn't been looked at yet labels Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new This issue hasn't been looked at yet
Projects
None yet
Development

No branches or pull requests

1 participant