pythonpep8multiple-arguments

How to pass "in-tuple multiple arguments" without violating pep8?


I have a game class and I need to pass screen width and height into pygame.display.set_mode() in __init__ method. It requires a tuple, for example - pygame.display.set_mode((width, height)).

I have also a second class named Settings from which I import width and height.

If I need to pass long name attributes inside a tuple, is it okay to write these double parentheses the way I did below not to exceed 79 chars? I'm not sure because I've never seen the double parentheses case in PEP8, only single.

def __init__(self):
    """Initialize the game, create game resources."""
    pygame.init()
    self.settings = Settings()
    self.screen = pygame.display.set_mode((
        self.settings.screen_width,
        self.settings.screen_height
    ))

Solution

  • You can use pycodestyle to check that your code is PEP8 compliant.

    If I copy-paste your code in a settings.py file, I can use

    pip install pycodestyle
    pycodestyle --show-source --show-pep8 settings.py
    

    which does not return anything, so you're good.

    However, as mentioned by CharlesDuffy, I suggest you to use a code formatter such as black to ensure consistent and PEP8 compliant code formatting.