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: cannot concatenate 'str' and 'int' objects #30

Closed
clokep opened this issue Apr 16, 2018 · 1 comment
Closed

TypeError: cannot concatenate 'str' and 'int' objects #30

clokep opened this issue Apr 16, 2018 · 1 comment

Comments

@clokep
Copy link

clokep commented Apr 16, 2018

With flake8-builtins 1.3.0 and flake8 3.5.0, I'm getting the following error on Python 2.7:

Traceback (most recent call last):
  File "/home/ubuntu/virtualenvs/venv-system/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 385, in _run
    self.report()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 376, in report
    self.report_errors()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/main/application.py", line 340, in report_errors
    results = self.file_checker_manager.report()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/checker.py", line 267, in report
    results_reported += self._handle_results(filename, results)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/checker.py", line 166, in _handle_results
    physical_line=physical_line,
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/flake8/style_guide.py", line 384, in handle_error
    error = Violation(code, filename, line_number, column_number + 1,
TypeError: cannot concatenate 'str' and 'int' objects

This seems to be while reporting the error? This seems new in 1.3.0, no error in 1.2.1.

@arnimarj
Copy link

I've run into the same issue. A debug session would indicate that the offending lines is in check_function_definition().

I updated check_function_definition() to be:

    def check_function_definition(self, statement):
        if statement.name in BUILTINS:
            msg = self.assign_msg
            if type(statement.__flake8_builtins_parent) is ast.ClassDef:
                msg = self.class_attribute_msg

            yield self.error(statement, message=msg, variable=statement.name)

        if sys.version_info >= (3, 0):
            for arg in statement.args.args:
                if isinstance(arg, ast.arg) and \
                        arg.arg in BUILTINS:
                    yield self.error(
                        arg,
                        message=self.argument_msg,
                        column=arg.col_offset,
                        variable=arg.arg,
                    )
        else:
            for arg in statement.args.args:
                if isinstance(arg, ast.Name) and \
                        arg.id in BUILTINS:
                    yield self.error(
                        arg,
                        message=self.argument_msg,
                        column=arg.col_offset,
                        variable=arg,
                    )

A small test case:

def func(self, format=None):
	pass

class obj(object):
	def func(self, format=None):
		pass

arnimarj added a commit to arnimarj/flake8-builtins that referenced this issue Apr 21, 2018
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