Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 67,464 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.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,464 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 67,464 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!