Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dictionary keys changed during iteration error seen in utils when using py3.8 #877

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions jira/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ class CaseInsensitiveDict(dict):
def __init__(self, *args, **kw):
super(CaseInsensitiveDict, self).__init__(*args, **kw)

self.itemlist = {}
for key, value in super(CaseInsensitiveDict, self).items():
if key != key.lower():
self[key.lower()] = value
self.pop(key, None)
# self.itemlist = {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not leave commented out code. Remove it if it's no longer necessary.

# for key, value in super(CaseInsensitiveDict, self).items():
# if key != key.lower():
# self[key.lower()] = value
# self.pop(key, None)

# self.itemlist[key.lower()] = value
itemlist = {}
for key, value in super(CaseInsensitiveDict, self).items():
itemlist[key.lower()] = value
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a list of keys to remove and remove them in subsequent for loop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. Yes, that would be clearer actually and appears to work fine too:

    def __init__(self, *args, **kw):
        super(CaseInsensitiveDict, self).__init__(*args, **kw)

        upper_keys_list = []
        for key in super(CaseInsensitiveDict, self).keys():
            if key != key.lower():
                upper_keys_list.append(key)

        for upper_key in upper_keys_list:
            self[upper_key.lower()] = self[upper_key]
            self.pop(upper_key, None)

self = itemlist


def __setitem__(self, key, value):
"""Overwrite [] implementation."""
Expand Down