Skip to content

Commit f4059c4

Browse files
jdufresneencukou
authored andcommitted
Prefer iterating dict instead of calling dict.keys()
Calling dict.keys() is unnecessary. iter(dict) is equivalent to dict.keys(). Inspired by Lennart Regebro's talk "Prehistoric Patterns in Python" from PyCon 2017. https://www.youtube.com/watch?v=V5-JH23Vk0I
1 parent 9346fa5 commit f4059c4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Lib/ldap/modlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def modifyModlist(
5050
case_ignore_attr_types = {v.lower() for v in case_ignore_attr_types or []}
5151
modlist = []
5252
attrtype_lower_map = {}
53-
for a in old_entry.keys():
53+
for a in old_entry:
5454
attrtype_lower_map[a.lower()]=a
5555
for attrtype, value in new_entry.items():
5656
attrtype_lower = attrtype.lower()

Lib/ldap/schema/subentry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
SCHEMA_CLASS_MAPPING[o.schema_attribute] = o
2424
SCHEMA_ATTR_MAPPING[o] = o.schema_attribute
2525

26-
SCHEMA_ATTRS = SCHEMA_CLASS_MAPPING.keys()
26+
SCHEMA_ATTRS = list(SCHEMA_CLASS_MAPPING)
2727

2828

2929
class SubschemaError(ValueError):
@@ -122,15 +122,15 @@ def __init__(self,sub_schema_sub_entry,check_uniqueness=1):
122122
self.sed[se_class][se_id] = se_instance
123123

124124
if hasattr(se_instance,'names'):
125-
for name in ldap.cidict.cidict({}.fromkeys(se_instance.names)).keys():
125+
for name in ldap.cidict.cidict({}.fromkeys(se_instance.names)):
126126
if check_uniqueness and name in self.name2oid[se_class]:
127127
self.non_unique_names[se_class][se_id] = None
128128
raise NameNotUnique(attr_value)
129129
else:
130130
self.name2oid[se_class][name] = se_id
131131

132132
# Turn dict into list maybe more handy for applications
133-
self.non_unique_oids = self.non_unique_oids.keys()
133+
self.non_unique_oids = list(self.non_unique_oids)
134134

135135
return # subSchema.__init__()
136136

@@ -168,7 +168,7 @@ def listall(self,schema_element_class,schema_element_filters=None):
168168
except AttributeError:
169169
pass
170170
else:
171-
result = avail_se.keys()
171+
result = list(avail_se)
172172
return result
173173

174174

@@ -422,14 +422,14 @@ def attribute_types(
422422

423423
# Remove all mandantory attribute types from
424424
# optional attribute type list
425-
for a in list(r_may.keys()):
425+
for a in list(r_may):
426426
if a in r_must:
427427
del r_may[a]
428428

429429
# Apply attr_type_filter to results
430430
if attr_type_filter:
431431
for l in [r_must,r_may]:
432-
for a in list(l.keys()):
432+
for a in list(l):
433433
for afk,afv in attr_type_filter:
434434
try:
435435
schema_attr_type = self.sed[AttributeType][a]

Tests/t_ldap_syncrepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def syncrepl_present(self, uuids, refreshDeletes=False):
242242

243243
elif (uuids is None) and (refreshDeletes is False):
244244
deleted_uuids = []
245-
for uuid in self.uuid_dn.keys():
245+
for uuid in self.uuid_dn:
246246
if uuid not in self.present:
247247
deleted_uuids.append(uuid)
248248

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy