GithubHelp home page GithubHelp logo

Comments (4)

jparise avatar jparise commented on June 1, 2024 3

Could you also share the snippet of code that's producing this issue? It appears to be around line 363 of the active file.

Assuming Python 2, I'm not familiar with the case where an ast.ExceptHandler's name attribute isn't an ast.Name node. Perhaps an old-style except: syntax?

from pep8-naming.

tim-ireland avatar tim-ireland commented on June 1, 2024 3

Thanks for the pointer! I tracked it down to the following code snippet. And yes this is with python 2.7.15

#!/usr/bin/python

import socket

try:
    data = socket.gethostbyaddr('127.0.0.1')
    hostname = data[0]
    ip_address = data[2][0]
except (socket.herror, socket.gaierror) as (errno, error_string):
    print errno, error_string

And this reproduces the issue:

[root@3cc3a5f9a39b /tmp]# flake8 -j 1 foo.py
Traceback (most recent call last):
  File "/opt/stackstorm/virtualenvs/stackstorm/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 384, in _run
    self.run_checks()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/main/application.py", line 310, in run_checks
    self.file_checker_manager.run()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 321, in run
    self.run_serial()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 305, in run_serial
    checker.run_checks()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 579, in run_checks
    self.run_ast_checks()
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/flake8/checker.py", line 493, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 158, in visit_tree
    for error in self.visit_tree(child):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 158, in visit_tree
    for error in self.visit_tree(child):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 154, in visit_tree
    for error in self.visit_node(node):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 175, in visit_node
    for error in visitor_method(node, parents, ignore_names):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 413, in visit_excepthandler
    for error in self._find_errors(node, parents):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 377, in _find_errors
    for name in _extract_names(assignment_target):
  File "/opt/stackstorm/virtualenvs/stackstorm/lib/python2.7/site-packages/pep8ext_naming.py", line 462, in _extract_names
    yield assignment_target.name.id
AttributeError: 'Tuple' object has no attribute 'id'```

from pep8-naming.

tim-ireland avatar tim-ireland commented on June 1, 2024

This code does actually work by the way, here's an invalid ip address

#!/usr/bin/python

import socket

try:
    data = socket.gethostbyaddr('127.0111.0.1')
    hostname = data[0]
    ip_address = data[2][0]
except (socket.herror, socket.gaierror) as (errno, error_string):
    print errno, error_string
[root@3cc3a5f9a39b tmp]# python foo.py
1 Unknown host

from pep8-naming.

tim-ireland avatar tim-ireland commented on June 1, 2024

Looks like both of these exceptions return a value as a Tuple:

"The accompanying value is a pair (error, string) representing an error returned by a library call"

https://docs.python.org/2/library/socket.html#socket.herror
https://docs.python.org/2/library/socket.html#socket.gaierror

from pep8-naming.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.