-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
updatated python 2 dict methods to python 3 #3200
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -136,7 +136,7 @@ def print_plugin_description(plugin, stat): | |||
print('Fields descriptions:') | |||
print('') | |||
time_since_update = False | |||
for field, description in iteritems(stat.fields_description): | |||
for field, description in stat.fields_description (): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As such it is not callable; the items methods of dict should be used: stat.fields_description.items()
@@ -15,7 +15,7 @@ | |||
|
|||
import threading | |||
|
|||
from glances.globals import iteritems, to_ascii | |||
#from glances.globals import iteritems, to_ascii |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback, the line could be removed.
@@ -159,7 +159,7 @@ def run(self): | |||
self.stop() | |||
return False | |||
|
|||
for k, v in iteritems(self.OPENSTACK_API_METADATA): | |||
for k, v in self.OPENSTACK_API_METADATA(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, as well, the items()
methods is expected.
@@ -271,7 +271,7 @@ def update_snmp(self): | |||
return self.stats | |||
|
|||
# Convert SNMP stats to float | |||
for key in iterkeys(stats): | |||
for key in .keys(stats): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather stats.keys()
: iterkeys
in Python 2 is replaced by the keys method in Python 3.
@@ -15,7 +15,7 @@ | |||
from itertools import chain | |||
|
|||
from glances import __version__, psutil_version | |||
from glances.globals import iteritems | |||
#from glances.globals import iteritems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@@ -172,7 +172,7 @@ def msg_curse(self, args=None, max_width=None): | |||
# | |||
shortcuts = [] | |||
collecting = False | |||
for k, v in iteritems(self.view_data): | |||
for k, v in self.view_data(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto; expecting self.view_data.items()
@@ -12,7 +12,7 @@ | |||
|
|||
import psutil | |||
|
|||
from glances.globals import iteritems | |||
#from glances.globals import iteritems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto; better to take the line off.
@@ -125,7 +125,7 @@ def update(self): | |||
self.reset() | |||
return stats | |||
|
|||
for key in iterkeys(stats): | |||
for key in .keys(stats): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto; the keys
method of dict.
@@ -330,14 +330,14 @@ def get_stats_snmp(self, bulk=False, snmp_oid=None): | |||
ret = {} | |||
if bulk: | |||
# Bulk request | |||
snmp_result = snmp_client.getbulk_by_oid(0, 10, *list(itervalues(snmp_oid))) | |||
snmp_result = snmp_client.getbulk_by_oid(0, 10, *list(.values(snmp_oid))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather: snmp_oid.values()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snmp_oid.values() rather than .values(snmp_oid) (typo).
logger.info(snmp_result) | ||
if len(snmp_oid) == 1: | ||
# Bulk command for only one OID | ||
# Note: key is the item indexed but the OID result | ||
for item in snmp_result: | ||
if iterkeys(item)[0].startswith(itervalues(snmp_oid)[0]): | ||
ret[iterkeys(snmp_oid)[0] + iterkeys(item)[0].split(itervalues(snmp_oid)[0])[1]] = itervalues( | ||
if .keys(item)[0].startswith(.values(snmp_oid)[0]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
@@ -347,7 +347,7 @@ def get_stats_snmp(self, bulk=False, snmp_oid=None): | |||
for item in snmp_result: | |||
item_stats = {} | |||
item_key = None | |||
for key in iterkeys(snmp_oid): | |||
for key in .keys(snmp_oid): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@@ -359,10 +359,10 @@ def get_stats_snmp(self, bulk=False, snmp_oid=None): | |||
index += 1 | |||
else: | |||
# Simple get request | |||
snmp_result = snmp_client.get_by_oid(*list(itervalues(snmp_oid))) | |||
snmp_result = snmp_client.get_by_oid(*list(.values(snmp_oid))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto; with the method values
on the dict snmp_oid
.
|
||
# Build the internal dict with the SNMP result | ||
for key in iterkeys(snmp_oid): | ||
for key in .keys(snmp_oid): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@@ -91,7 +91,7 @@ def msg_curse(self, args=None, max_width=None): | |||
msg = '{:>7}'.format('Avail') | |||
ret.append(self.curse_add_line(msg)) | |||
# Data | |||
arrays = sorted(iterkeys(self.stats)) | |||
arrays = sorted(.keys(self.stats)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well; the method keys
should be called on self.stats
@@ -128,7 +128,7 @@ def msg_curse(self, args=None, max_width=None): | |||
ret.append(self.curse_new_line()) | |||
msg = '└─ Status {}'.format(array_stats['status']) | |||
ret.append(self.curse_add_line(msg, status)) | |||
components = sorted(iterkeys(array_stats['components'])) | |||
components = sorted(.keys(array_stats['components'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
@@ -13,7 +13,7 @@ | |||
import platform | |||
import re | |||
|
|||
from glances.globals import iteritems | |||
#from glances.globals import iteritems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be taken off.
@@ -139,7 +139,7 @@ def update_stats_with_snmp(self): | |||
|
|||
# Windows OS tips | |||
if self.short_system_name == 'windows': | |||
for key, value in iteritems(snmp_to_human['windows']): | |||
for key, value in snmp_to_human['windows'](): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather: snmp_to_human['windows'].items()
@@ -11,7 +11,7 @@ | |||
from copy import deepcopy | |||
from typing import Any, Optional | |||
|
|||
from glances.globals import iteritems | |||
#from glances.globals import iteritems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed.
@@ -178,7 +178,7 @@ def update(self) -> list[dict]: | |||
def update_local(self): | |||
"""Update stats localy""" | |||
stats = [] | |||
for engine, watcher in iteritems(self.watchers): | |||
for engine, watcher in self.watchers(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.watchers.items()
Hello @fithacker97, I linked the PR to each corresponding file in #3181. |
The PR should be reworked, lots of type .keys and .values without variables before in the code. cc: @ariel-anieli / @fithacker97 |
Description
Title : Fitx python3 compatibility : replaced deparceted dict methods
Resume