Skip to content

Commit bb802b6

Browse files
committed
Prefer literals throughout project
- Use a dict literal instead of calling dict(). - Use a list literal instead of calling list(). - Use a set literal instead of calling set(). - Use a tuple literal instead of calling tuple(). - Use dict comprehension These syntax expressions are available by all supported Python versions. Literals are always faster than calling the constructor. More idiomatic with wider Python community.
1 parent 673957d commit bb802b6

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

Demo/pyasn1/syncrepl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def __init__(self, db_path, *args, **kwargs):
4545
if db_path:
4646
self.__data = shelve.open(db_path, 'c')
4747
else:
48-
self.__data = dict()
48+
self.__data = {}
4949
# We need this for later internal use
50-
self.__presentUUIDs = dict()
50+
self.__presentUUIDs = {}
5151

5252
def close_db(self):
5353
# Close the data store properly to avoid corruption
@@ -64,7 +64,7 @@ def syncrepl_entry(self, dn, attributes, uuid):
6464
logger.debug('dn=%r attributes=%r uuid=%r', dn, attributes, uuid)
6565
# First we determine the type of change we have here
6666
# (and store away the previous data for later if needed)
67-
previous_attributes = dict()
67+
previous_attributes = {}
6868
if uuid in self.__data:
6969
change_type = 'modify'
7070
previous_attributes = self.__data[uuid]

Lib/ldap/asyncsearch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
from ldap import __version__
1010

11-
SEARCH_RESULT_TYPES = set([
11+
SEARCH_RESULT_TYPES = {
1212
ldap.RES_SEARCH_ENTRY,
1313
ldap.RES_SEARCH_RESULT,
1414
ldap.RES_SEARCH_REFERENCE,
15-
])
15+
}
1616

17-
ENTRY_RESULT_TYPES = set([
17+
ENTRY_RESULT_TYPES = {
1818
ldap.RES_SEARCH_ENTRY,
1919
ldap.RES_SEARCH_RESULT,
20-
])
20+
}
2121

2222

2323
class WrongResultType(Exception):
@@ -207,7 +207,7 @@ class IndexedDict(Dict):
207207

208208
def __init__(self,l,indexed_attrs=None):
209209
Dict.__init__(self,l)
210-
self.indexed_attrs = indexed_attrs or tuple()
210+
self.indexed_attrs = indexed_attrs or ()
211211
self.index = {}.fromkeys(self.indexed_attrs,{})
212212

213213
def _processSingleResult(self,resultType,resultItem):

Lib/ldap/controls/deref.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def decodeControlValue(self,encodedControlValue):
107107
self.derefRes = {}
108108
for deref_res in decodedValue:
109109
deref_attr,deref_val,deref_vals = deref_res[0],deref_res[1],deref_res[2]
110-
partial_attrs_dict = dict([
111-
(str(tv[0]),map(str,tv[1]))
110+
partial_attrs_dict = {
111+
str(tv[0]): map(str,tv[1])
112112
for tv in deref_vals or []
113-
])
113+
}
114114
try:
115115
self.derefRes[str(deref_attr)].append((str(deref_val),partial_attrs_dict))
116116
except KeyError:

Lib/ldap/controls/psearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
'modify':4,
3333
'modDN':8,
3434
}
35-
CHANGE_TYPES_STR = dict([(v,k) for k,v in CHANGE_TYPES_INT.items()])
35+
CHANGE_TYPES_STR = {v: k for k,v in CHANGE_TYPES_INT.items()}
3636

3737

3838
class PersistentSearchControl(RequestControl):

Lib/ldap/ldapobject.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ def _bytesify_result_value(self, result_value):
227227
return result_value
228228
if hasattr(result_value, 'items'):
229229
# It's a attribute_name: [values] dict
230-
return dict(
231-
(self._maybe_rebytesify_text(key), value)
230+
return {
231+
self._maybe_rebytesify_text(key): value
232232
for (key, value) in result_value.items()
233-
)
233+
}
234234
elif isinstance(result_value, bytes):
235235
return result_value
236236
else:
@@ -991,13 +991,13 @@ class ReconnectLDAPObject(SimpleLDAPObject):
991991
application.
992992
"""
993993

994-
__transient_attrs__ = set([
994+
__transient_attrs__ = {
995995
'_l',
996996
'_ldap_object_lock',
997997
'_trace_file',
998998
'_reconnect_lock',
999999
'_last_bind',
1000-
])
1000+
}
10011001

10021002
def __init__(
10031003
self,uri,
@@ -1025,11 +1025,11 @@ def __init__(
10251025

10261026
def __getstate__(self):
10271027
"""return data representation for pickled object"""
1028-
state = dict([
1029-
(k,v)
1028+
state = {
1029+
k: v
10301030
for k,v in self.__dict__.items()
10311031
if k not in self.__transient_attrs__
1032-
])
1032+
}
10331033
state['_last_bind'] = self._last_bind[0].__name__, self._last_bind[1], self._last_bind[2]
10341034
return state
10351035

Lib/ldap/schema/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from ldap.schema.tokenizer import split_tokens,extract_tokens
1313

14-
NOT_HUMAN_READABLE_LDAP_SYNTAXES = set([
14+
NOT_HUMAN_READABLE_LDAP_SYNTAXES = {
1515
'1.3.6.1.4.1.1466.115.121.1.4', # Audio
1616
'1.3.6.1.4.1.1466.115.121.1.5', # Binary
1717
'1.3.6.1.4.1.1466.115.121.1.8', # Certificate
@@ -21,7 +21,7 @@
2121
'1.3.6.1.4.1.1466.115.121.1.28', # JPEG
2222
'1.3.6.1.4.1.1466.115.121.1.40', # Octet String
2323
'1.3.6.1.4.1.1466.115.121.1.49', # Supported Algorithm
24-
])
24+
}
2525

2626

2727
class SchemaElement:

Lib/ldap/syncrepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def __init__(self, encodedMessage):
323323
self.newcookie = str(comp)
324324
return
325325

326-
val = dict()
326+
val = {}
327327

328328
cookie = comp.getComponentByName('cookie')
329329
if cookie.hasValue():

Lib/ldif.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def list_dict(l):
6969
"""
7070
return a dictionary with all items of l being the keys of the dictionary
7171
"""
72-
return dict([(i,None) for i in l])
72+
return {i: None for i in l}
7373

7474

7575
class LDIFWriter:

Tests/t_ldap_syncrepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def syncrepl_present(self, uuids, refreshDeletes=False):
247247
self.present.extend(uuids)
248248

249249
elif (uuids is None) and (refreshDeletes is False):
250-
deleted_uuids = list()
250+
deleted_uuids = []
251251
for uuid in self.uuid_dn.keys():
252252
if uuid not in self.present:
253253
deleted_uuids.append(uuid)

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ class OpenLDAP2:
7171
# setup() in a fashion that doesn't break compatibility to
7272
# distutils. This still allows 'normal' builds where either
7373
# Python > 2.3.5 or setuptools (or both ;o) are not available.
74-
kwargs = dict()
74+
kwargs = {}
7575
if has_setuptools:
76-
kwargs = dict(
77-
include_package_data = True,
78-
install_requires = [
76+
kwargs = {
77+
'include_package_data': True,
78+
'install_requires': [
7979
'setuptools',
8080
'pyasn1 >= 0.3.7',
8181
'pyasn1_modules >= 0.1.5',
8282
],
83-
zip_safe = False,
84-
python_requires = '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*',
85-
)
83+
'zip_safe': False,
84+
'python_requires': '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*',
85+
}
8686

8787
setup(
8888
#-- Package description

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