]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #22823: Use set literals instead of creating a set from a list
authorRaymond Hettinger <python@rcn.com>
Sun, 9 Nov 2014 23:56:33 +0000 (15:56 -0800)
committerRaymond Hettinger <python@rcn.com>
Sun, 9 Nov 2014 23:56:33 +0000 (15:56 -0800)
Doc/howto/logging-cookbook.rst
Doc/library/pickle.rst
Lib/_strptime.py
Lib/asyncore.py
Lib/ipaddress.py
Lib/mailbox.py
Lib/sre_compile.py
Lib/sre_parse.py
Lib/statistics.py
Parser/asdl.py

index e77e73077bf699936bc139b5b9df4f63abfb51ff..7205566609d89b4c6ff2c79f44597e18dec5efd8 100644 (file)
@@ -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()
index 47356f9f0cfe5316134f9ed8e8318f499f1013f2..4ce4d345af4590d13da447a6a1866ccbf2215a76 100644 (file)
@@ -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:
index 53bd34be806d21ca61735f8affdcd56c7a1fd2a1..42f23d3d54b9b414658f6a7a3e7f83801fb236a9 100644 (file)
@@ -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)
index da24b3843b3cd4e1bd5dc778f1feeb27fc050fa3..68efd45f858a989364ffb64684c65da7ed8be825 100644 (file)
@@ -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:
index ced9e7953bc3c31fdaad0ffd46da3b6a7b7bc4c3..d15a1d923fcbfac30e7aa9a68faeb86d835d4282 100644 (file)
@@ -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
index 2eee76cfe50799a0b646ec387b8e1f5fff9eded4..145b2040c9b761f535c14b56a958b6f642de6d82 100644 (file)
@@ -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."""
index 1b3e9f82e349c8af59b4b924f7c9ea939d219dfe..3b632ed9263042d3cb478455df79b919def085bb 100644 (file)
@@ -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
index edc3ff143ac464361e594c46946cea84d1b4e724..57b15e7be3871b5f621ae198b048169ef2e9910a 100644 (file)
@@ -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")),
index 25a26d4aa713bfe8551667d4dc86a57aff2b66ea..3972ed2e5f7ec0278bd4c32863d07a1abf25f0a4 100644 (file)
@@ -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])
index 4618416c57ae314ab7bc2fdda033e423db957c9f..121cdab952037dc0c77d93c73381d82000cc215e 100644 (file)
@@ -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):