Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df1b699

Browse files
committed
Issue python#22823: Use set literals instead of creating a set from a list
1 parent bf764a1 commit df1b699

10 files changed

Lines changed: 19 additions & 20 deletions

File tree

Doc/howto/logging-cookbook.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ as in the following complete example::
16801680

16811681
def main():
16821682
logging.basicConfig(level=logging.INFO, format='%(message)s')
1683-
logging.info(_('message 1', set_value=set([1, 2, 3]), snowman='\u2603'))
1683+
logging.info(_('message 1', set_value={1, 2, 3}, snowman='\u2603'))
16841684

16851685
if __name__ == '__main__':
16861686
main()

Doc/library/pickle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ For the simplest code, use the :func:`dump` and :func:`load` functions. ::
859859
data = {
860860
'a': [1, 2.0, 3, 4+6j],
861861
'b': ("character string", b"byte string"),
862-
'c': set([None, True, False])
862+
'c': {None, True, False}
863863
}
864864

865865
with open('data.pickle', 'wb') as f:

Lib/_strptime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ def __calc_timezone(self):
167167
time.tzset()
168168
except AttributeError:
169169
pass
170-
no_saving = frozenset(["utc", "gmt", time.tzname[0].lower()])
170+
no_saving = frozenset({"utc", "gmt", time.tzname[0].lower()})
171171
if time.daylight:
172-
has_saving = frozenset([time.tzname[1].lower()])
172+
has_saving = frozenset({time.tzname[1].lower()})
173173
else:
174174
has_saving = frozenset()
175175
self.timezone = (no_saving, has_saving)

Lib/asyncore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
5858
errorcode
5959

60-
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
61-
EBADF))
60+
_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
61+
EBADF})
6262

6363
try:
6464
socket_map
@@ -220,7 +220,7 @@ class dispatcher:
220220
connecting = False
221221
closing = False
222222
addr = None
223-
ignore_log_types = frozenset(['warning'])
223+
ignore_log_types = frozenset({'warning'})
224224

225225
def __init__(self, sock=None, map=None):
226226
if map is None:

Lib/ipaddress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ class _BaseV4:
10881088
_DECIMAL_DIGITS = frozenset('0123456789')
10891089

10901090
# the valid octets for host and netmasks. only useful for IPv4.
1091-
_valid_mask_octets = frozenset((255, 254, 252, 248, 240, 224, 192, 128, 0))
1091+
_valid_mask_octets = frozenset({255, 254, 252, 248, 240, 224, 192, 128, 0})
10921092

10931093
_max_prefixlen = IPV4LENGTH
10941094
# There are only a handful of valid v4 netmasks, so we cache them all

Lib/mailbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,8 @@ def _dump_sequences(self, message, key):
12301230
class Babyl(_singlefileMailbox):
12311231
"""An Rmail-style Babyl mailbox."""
12321232

1233-
_special_labels = frozenset(('unseen', 'deleted', 'filed', 'answered',
1234-
'forwarded', 'edited', 'resent'))
1233+
_special_labels = frozenset({'unseen', 'deleted', 'filed', 'answered',
1234+
'forwarded', 'edited', 'resent'})
12351235

12361236
def __init__(self, path, factory=None, create=True):
12371237
"""Initialize a Babyl mailbox."""

Lib/sre_compile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
else:
2323
MAXCODE = 0xFFFFFFFF
2424

25-
_LITERAL_CODES = set([LITERAL, NOT_LITERAL])
26-
_REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT])
27-
_SUCCESS_CODES = set([SUCCESS, FAILURE])
28-
_ASSERT_CODES = set([ASSERT, ASSERT_NOT])
25+
_LITERAL_CODES = {LITERAL, NOT_LITERAL}
26+
_REPEATING_CODES = {REPEAT, MIN_REPEAT, MAX_REPEAT}
27+
_SUCCESS_CODES = {SUCCESS, FAILURE}
28+
_ASSERT_CODES = {ASSERT, ASSERT_NOT}
2929

3030
def _compile(code, pattern, flags):
3131
# internal: compile a (sub)pattern

Lib/sre_parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
WHITESPACE = frozenset(" \t\n\r\v\f")
2727

28-
_REPEATCODES = frozenset((MIN_REPEAT, MAX_REPEAT))
29-
_UNITCODES = frozenset((ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY))
28+
_REPEATCODES = frozenset({MIN_REPEAT, MAX_REPEAT})
29+
_UNITCODES = frozenset({ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY})
3030

3131
ESCAPES = {
3232
r"\a": (LITERAL, ord("\a")),

Lib/statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _sum(data, start=0):
150150
# We fail as soon as we reach a value that is not an int or the type of
151151
# the first value which is not an int. E.g. _sum([int, int, float, int])
152152
# is okay, but sum([int, int, float, Fraction]) is not.
153-
allowed_types = set([int, type(start)])
153+
allowed_types = {int, type(start)}
154154
n, d = _exact_ratio(start)
155155
partials = {d: n} # map {denominator: sum of numerators}
156156
# Micro-optimizations.
@@ -168,7 +168,7 @@ def _sum(data, start=0):
168168
assert allowed_types.pop() is int
169169
T = int
170170
else:
171-
T = (allowed_types - set([int])).pop()
171+
T = (allowed_types - {int}).pop()
172172
if None in partials:
173173
assert issubclass(T, (float, Decimal))
174174
assert not math.isfinite(partials[None])

Parser/asdl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
# See the EBNF at the top of the file to understand the logical connection
3434
# between the various node types.
3535

36-
builtin_types = set(
37-
['identifier', 'string', 'bytes', 'int', 'object', 'singleton'])
36+
builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton'}
3837

3938
class AST:
4039
def __repr__(self):

0 commit comments

Comments
 (0)