Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Write Better Python Cleaner Code PEP 8

Does anyone know what this error means?

I made all of the changes that Kenneth made to the badpep8.py file, but I'm getting one extra error that wasn't in the video.

Here's the code:

# multiple imports
def foo_bar(arg1, arg2, arg3, arg4):
    # way too much indentation
    return arg1, arg2, arg3, arg4


def bar(*args):
    # bad spacing
    return 2 + 2


# Bad class name, bad spacing, bad indentation
class Treehouse:
    def one(self):
        return 1

    def two(self):
        return 2


# bad identation and whitespace
alpha, beta, charlie, delta = foo_bar(
    "a long string",
    "a longer string",
    "yet another long string",
    "and other crazy string")


# bad spacing
one = 1
three = 3
fourteen = 14   # make fourteen equal to 12

print(alpha)
print(fourteen)

print(Treehouse().two())

When I run flake8 badpep8.py in the console, I get the following message: /usr/local/lib/python3.9/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1 EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')

Does anyone know what this is? Any help would be much appreciated! :)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Marking as feedback.

Developers: Please add to Teacher's Notes:

pep8 has been renamed to pycodestyle
Please install and use `pycodestyle` instead

The standard Workspace for this video might need updating as well.

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Amy Murphy, the short answer is โ€œwhitespace found after an opening paren, square or curly bracket, or whitespace found before a paren, square or curly bracket, comma, semi-colon, or colonโ€

Looking at the call to foo_bar the parens around the arguments have this whitespace before the first argument.

Longer answer, the regex is looking for two cases. Breaking down the regex;

r'[[({] | []}),;:]'
r'set1 with two cases'
r'[case1|case2]' # set1: case1 or case2
r'[({] ' # case1
r'set2 followed by space โ€˜ # case1
r'[({]' # set2: open paren, open curly bracket, or open

r' []}),;:]' # case2
r'space followed by set3' # case2
r'[]}),;:]' # set3: closing bracket, comma, semi-colon, or colon

Thanks, Chris! Any tips on how to resolve the issue?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I get this error running pep8 on your code:

Warning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
.../lib/python3.8/site-packages/pep8.py:2123: UserWarning: 

pep8 has been renamed to pycodestyle (GitHub issue #466)       # <<<
Use of the pep8 tool will be removed in a future release.      # <<<
Please install and use `pycodestyle` instead.                  # <<<

Looking the whole error message, it looks like pep8 has be deprecated. The last version of pep8 was 1.7.1 (2017-10-22) where the deprecation warning was added. Using pycodestyle is the new solution.

I have installed (python -m pip install pycodestyle) and run pycodestyle locally on your code and it passes cleanly.

Thanks!

Oscar Gomez
Oscar Gomez
6,797 Points
# import sys  #unused
# import random  #unused


def foo_bar(arg1, arg2, arg3, arg4):
    # way too much indentation
    return arg1, arg2, arg3, arg4


def bar(*args):
    # bad spacing
    return 2 + 2


# Bad class name, bad spacing, bad indentation
class Treehouse:
    def one(self):
        return 1 

    def two(self):
        return 2


# bad identation and whitespace
alpha, beta, charlie, delta = foo_bar(
    "a long string",
    "a longer string",
    "yet another long string",
    "and other crazy string")


# bad spacing
one = 1
three = 3
fourteen = 14  # make fourteen equal to 12

print(alpha)
print(fourteen)

print(Treehouse().two())

# import pep8
# checker =  pep8.Checker('badpep8.py')
# checker.check_all()
Oscar Gomez
Oscar Gomez
6,797 Points

getting same error as Amy:

flake8 badpep8.py
/usr/local/lib/python3.9/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

See comment above about installs pycodestyle.

Post back if you need more help. Good luck!!!