Skip to content

Adding new attribute fails in case new name is the last in the list #1806

@karsten-wagner

Description

@karsten-wagner

Problem Statement

$ python scripts/add_attribute.py Permissions triage bool
Traceback (most recent call last):
  File "<...>\PyGithub\scripts\add_attribute.py", line 124, in <module>
    line = lines[i].rstrip()
IndexError: list index out of range

--> Adding a new attribute at the end of the existing list of attributes in class Permissions fails.
--> In this case the last attribute name was "push", so "triage" comes last.

def push(self):
"""
:type: bool
"""
return self._push.value
def _initAttributes(self):
self._admin = github.GithubObject.NotSet
self._pull = github.GithubObject.NotSet
self._push = github.GithubObject.NotSet

Solution Approach

In case the new attribute name will result in adding it at the end of the list of attributes, then the processing within the script at https://github.com/PyGithub/PyGithub/blob/master/scripts/add_attribute.py#L89 was already processing the next source code line which already contains the _initAttributes function.
Subsequently at https://github.com/PyGithub/PyGithub/blob/master/scripts/add_attribute.py#L122 inInit is set to False, but only checked again after reading already the next line. This means the following code block will never again notice the place of the _initAttributes and fails at the end of the file due to endless loop.

Problem can be fixed by conditionally remembering we already reached the _initAttributes function, so replace:

inInit = False

with

inInit = True if line == "    def _initAttributes(self):" else False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions