-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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.
PyGithub/github/Permissions.py
Lines 63 to 72 in 34d097c
| 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:
PyGithub/scripts/add_attribute.py
Line 122 in 34d097c
| inInit = False |
with
inInit = True if line == " def _initAttributes(self):" else False