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

TypeError: unsupported operand type(s) for +: 'int' and 'dict' #73

Closed
tbekolay opened this issue Jun 21, 2019 · 6 comments
Closed

TypeError: unsupported operand type(s) for +: 'int' and 'dict' #73

tbekolay opened this issue Jun 21, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@tbekolay
Copy link

I attempted to run wily build nengo/ on the master branch of https://github.com/nengo/nengo and I get the following error:

~/C/nengo (nengo) wily build nengo/                                           (master) 
Found 50 revisions from 'git' archiver in '/home/tbekolay/Code/nengo'.
Running operators - maintainability,halstead,cyclomatic,raw
Processing |                                | 1/200Failed to build cache: 'unsupported operand type(s) for +: 'int' and 'dict''
Traceback (most recent call last):
  File "/home/tbekolay/.virtualenvs/nengo/bin/wily", line 10, in <module>
    sys.exit(cli())
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/__main__.py", line 132, in build
    operators=resolve_operators(config.operators),
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/commands/build.py", line 127, in build
    raise e
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/commands/build.py", line 116, in build
    result[str(root)][metric.name] = func(values)
TypeError: unsupported operand type(s) for +: 'int' and 'dict'

This is a little puzzling since the line that it's pointing to doesn't contain an addition statement, as far as I can tell.

This was run in a Python 3.7 virtual environment with wily version 1.12.2. Let me know if I can provide any more information to help with debugging.

@tonybaloney
Copy link
Owner

each of the operators have a sum method, which should be initialised to 0.

the final line (causing the error) is compiling the values together.

It should be getting an int from radon, but there have been some new releases of radon, so I wonder if this has changed the API.

@tonybaloney
Copy link
Owner

please can you run wily --debug build nengo/ and paste the output back into this issue

@tbekolay
Copy link
Author

$ wily --debug build nengo/
Could not locate wily.cfg, using default config.
Fixing path to /home/tbekolay/Code/nengo
Loaded configuration from wily.cfg
Fixing archiver to git
Fixing targets to ('/home/tbekolay/Code/nengo/nengo',)
Using git archiver module
Initialised state indexes for archivers ['git']
Generating cache for /home/tbekolay/Code/nengo
Cache path is /home/tbekolay/.wily/5208d4c45
Wily cache not found, creating.
Creating wily cache /home/tbekolay/.wily/5208d4c45
Created wily cache
Found 50 revisions from 'git' archiver in '/home/tbekolay/Code/nengo'.
Running operators - halstead,cyclomatic,maintainability,raw
Using ('/home/tbekolay/Code/nengo/nengo',) with {'exclude': None, 'ignore': None, 'min': 'A', 'max': 'C', 'multi': True, 'show': False, 'sort': False, 'by_function': True} for HC metrics
Using ('/home/tbekolay/Code/nengo/nengo',) with {'exclude': None, 'ignore': None, 'min': 'A', 'max': 'F', 'no_assert': True, 'show_closures': False, 'order': <function <lambda> at 0x7f56d9597680>} for CC metrics
Running halstead operator on f61bb2d0ec2e5b1fc12f6e67a9d56652830c24d5
Running cyclomatic operator on f61bb2d0ec2e5b1fc12f6e67a9d56652830c24d5
Running halstead harvester
Running CC harvester
Using ('/home/tbekolay/Code/nengo/nengo',) with {'exclude': None, 'ignore': None, 'min': 'A', 'max': 'C', 'multi': True, 'show': False, 'sort': False} for MI metrics
Using ('/home/tbekolay/Code/nengo/nengo',) with {'exclude': None, 'ignore': None, 'summary': False} for Raw metrics
Running maintainability operator on f61bb2d0ec2e5b1fc12f6e67a9d56652830c24d5
Running raw operator on f61bb2d0ec2e5b1fc12f6e67a9d56652830c24d5
Running maintainability harvester
Running raw harvester
Failed to build cache: 'unsupported operand type(s) for +: 'int' and 'dict''
Traceback (most recent call last):
  File "/home/tbekolay/.virtualenvs/nengo/bin/wily", line 10, in <module>
    sys.exit(cli())
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/__main__.py", line 132, in build
    operators=resolve_operators(config.operators),
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/commands/build.py", line 127, in build
    raise e
  File "/home/tbekolay/.virtualenvs/nengo/lib/python3.7/site-packages/wily/commands/build.py", line 116, in build
    result[str(root)][metric.name] = func(values)
TypeError: unsupported operand type(s) for +: 'int' and 'dict'

Hope that helps!

@tonybaloney tonybaloney added the bug Something isn't working label Sep 17, 2019
@alegonz
Copy link
Contributor

alegonz commented Sep 21, 2019

Hello,

I stumbled upon the same bug recently and after some debugging I found a simple yet critical bug: file metric aggregates and object metrics are mangled in the results dictionary if the file happens to include objects that have the same name as the metrics (e.g. a function called h1).

Specifically, this happens in the haldstead.py module in lines 79~86. The cyclomatic.py module has a similar issue, where the statement in line 94 would overwrite the metrics of any object that happened to be named complexity.

I came up with a simple solution which is to add an extra level in the results dict for detailed and total metrics, i.e.:

results[filename]["detailed"][function] = self._report_to_dict(report)
...
results[filename]["total"] = self._report_to_dict(instance)

I got it to work in the build case, but I also need to fix the diff and report cases accordingly.
I got it to work and tests pass. If the above sounds good I can throw a PR, I'd be happy to help :)

@tonybaloney
Copy link
Owner

@alegonz a PR would be amazing, I've struggled to reproduce this effectively to narrow down the issue but it sounds like you have

@tonybaloney
Copy link
Owner

Fixed in 1.12.4. Users may need to update their cache, but wily gives this warning automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
3 participants