summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-11-09 23:56:33 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-11-09 23:56:33 (GMT)
commitdf1b69944796caa6854049caf624d32c408c27d5 (patch)
tree655332d48c8fd87bbc06e5e624238342c4ebdb94
parentbf764a1912b084e5fc9acd6cb160e66060bc368a (diff)
downloadcpython-df1b69944796caa6854049caf624d32c408c27d5.zip
cpython-df1b69944796caa6854049caf624d32c408c27d5.tar.gz
cpython-df1b69944796caa6854049caf624d32c408c27d5.tar.bz2
Issue #22823: Use set literals instead of creating a set from a list
-rw-r--r--Doc/howto/logging-cookbook.rst2
-rw-r--r--Doc/library/pickle.rst2
-rw-r--r--Lib/_strptime.py4
-rw-r--r--Lib/asyncore.py6
-rw-r--r--Lib/ipaddress.py2
-rw-r--r--Lib/mailbox.py4
-rw-r--r--Lib/sre_compile.py8
-rw-r--r--Lib/sre_parse.py4
-rw-r--r--Lib/statistics.py4
-rw-r--r--Parser/asdl.py3
10 files changed, 19 insertions, 20 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index e77e730..7205566 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -1680,7 +1680,7 @@ as in the following complete example::
def main():
logging.basicConfig(level=logging.INFO, format='%(message)s')
- logging.info(_('message 1', set_value=set([1, 2, 3]), snowman='\u2603'))
+ logging.info(_('message 1', set_value={1, 2, 3}, snowman='\u2603'))
if __name__ == '__main__':
main()
diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst
index 47356f9..4ce4d34 100644
--- a/Doc/library/pickle.rst
+++ b/Doc/library/pickle.rst
@@ -859,7 +859,7 @@ For the simplest code, use the :func:`dump` and :func:`load` functions. ::
data = {
'a': [1, 2.0, 3, 4+6j],
'b': ("character string", b"byte string"),
- 'c': set([None, True, False])
+ 'c': {None, True, False}
}
with open('data.pickle', 'wb') as f:
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 53bd34b..42f23d3 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -167,9 +167,9 @@ class LocaleTime(object):
time.tzset()
except AttributeError:
pass
- no_saving = frozenset(["utc", "gmt", time.tzname[0].lower()])
+ no_saving = frozenset({"utc", "gmt", time.tzname[0].lower()})
if time.daylight:
- has_saving = frozenset([time.tzname[1].lower()])
+ has_saving = frozenset({time.tzname[1].lower()})
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index da24b38..68efd45 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -57,8 +57,8 @@ from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
errorcode
-_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
- EBADF))
+_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
+ EBADF})
try:
socket_map
@@ -220,7 +220,7 @@ class dispatcher:
connecting = False
closing = False
addr = None
- ignore_log_types = frozenset(['warning'])
+ ignore_log_types = frozenset({'warning'})
def __init__(self, sock=None, map=None):
if map is None:
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index ced9e79..d15a1d9 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -1088,7 +1088,7 @@ class _BaseV4:
_DECIMAL_DIGITS = frozenset('0123456789')
# the valid octets for host and netmasks. only useful for IPv4.
- _valid_mask_octets = frozenset((255, 254, 252, 248, 240, 224, 192, 128, 0))
+ _valid_mask_octets = frozenset({255, 254, 252, 248, 240, 224, 192, 128, 0})
_max_prefixlen = IPV4LENGTH
# There are only a handful of valid v4 netmasks, so we cache them all
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 2eee76c..145b204 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -1230,8 +1230,8 @@ class MH(Mailbox):
class Babyl(_singlefileMailbox):
"""An Rmail-style Babyl mailbox."""
- _special_labels = frozenset(('unseen', 'deleted', 'filed', 'answered',
- 'forwarded', 'edited', 'resent'))
+ _special_labels = frozenset({'unseen', 'deleted', 'filed', 'answered',
+ 'forwarded', 'edited', 'resent'})
def __init__(self, path, factory=None, create=True):
"""Initialize a Babyl mailbox."""
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 1b3e9f8..3b632ed 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -22,10 +22,10 @@ if _sre.CODESIZE == 2:
else:
MAXCODE = 0xFFFFFFFF
-_LITERAL_CODES = set([LITERAL, NOT_LITERAL])
-_REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT])
-_SUCCESS_CODES = set([SUCCESS, FAILURE])
-_ASSERT_CODES = set([ASSERT, ASSERT_NOT])
+_LITERAL_CODES = {LITERAL, NOT_LITERAL}
+_REPEATING_CODES = {REPEAT, MIN_REPEAT, MAX_REPEAT}
+_SUCCESS_CODES = {SUCCESS, FAILURE}
+_ASSERT_CODES = {ASSERT, ASSERT_NOT}
def _compile(code, pattern, flags):
# internal: compile a (sub)pattern
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index edc3ff1..57b15e7 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -25,8 +25,8 @@ HEXDIGITS = frozenset("0123456789abcdefABCDEF")
WHITESPACE = frozenset(" \t\n\r\v\f")
-_REPEATCODES = frozenset((MIN_REPEAT, MAX_REPEAT))
-_UNITCODES = frozenset((ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY))
+_REPEATCODES = frozenset({MIN_REPEAT, MAX_REPEAT})
+_UNITCODES = frozenset({ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY})
ESCAPES = {
r"\a": (LITERAL, ord("\a")),
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 25a26d4..3972ed2 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -150,7 +150,7 @@ def _sum(data, start=0):
# We fail as soon as we reach a value that is not an int or the type of
# the first value which is not an int. E.g. _sum([int, int, float, int])
# is okay, but sum([int, int, float, Fraction]) is not.
- allowed_types = set([int, type(start)])
+ allowed_types = {int, type(start)}
n, d = _exact_ratio(start)
partials = {d: n} # map {denominator: sum of numerators}
# Micro-optimizations.
@@ -168,7 +168,7 @@ def _sum(data, start=0):
assert allowed_types.pop() is int
T = int
else:
- T = (allowed_types - set([int])).pop()
+ T = (allowed_types - {int}).pop()
if None in partials:
assert issubclass(T, (float, Decimal))
assert not math.isfinite(partials[None])
diff --git a/Parser/asdl.py b/Parser/asdl.py
index 4618416..121cdab 100644
--- a/Parser/asdl.py
+++ b/Parser/asdl.py
@@ -33,8 +33,7 @@ __all__ = [
# See the EBNF at the top of the file to understand the logical connection
# between the various node types.
-builtin_types = set(
- ['identifier', 'string', 'bytes', 'int', 'object', 'singleton'])
+builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton'}
class AST:
def __repr__(self):