mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Issue #22823: Use set literals instead of creating a set from a list
This commit is contained in:
parent
bf764a1912
commit
df1b699447
10 changed files with 19 additions and 20 deletions
|
@ -1680,7 +1680,7 @@ as in the following complete example::
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -859,7 +859,7 @@ For the simplest code, use the :func:`dump` and :func:`load` functions. ::
|
||||||
data = {
|
data = {
|
||||||
'a': [1, 2.0, 3, 4+6j],
|
'a': [1, 2.0, 3, 4+6j],
|
||||||
'b': ("character string", b"byte string"),
|
'b': ("character string", b"byte string"),
|
||||||
'c': set([None, True, False])
|
'c': {None, True, False}
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('data.pickle', 'wb') as f:
|
with open('data.pickle', 'wb') as f:
|
||||||
|
|
|
@ -167,9 +167,9 @@ class LocaleTime(object):
|
||||||
time.tzset()
|
time.tzset()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
no_saving = frozenset(["utc", "gmt", time.tzname[0].lower()])
|
no_saving = frozenset({"utc", "gmt", time.tzname[0].lower()})
|
||||||
if time.daylight:
|
if time.daylight:
|
||||||
has_saving = frozenset([time.tzname[1].lower()])
|
has_saving = frozenset({time.tzname[1].lower()})
|
||||||
else:
|
else:
|
||||||
has_saving = frozenset()
|
has_saving = frozenset()
|
||||||
self.timezone = (no_saving, has_saving)
|
self.timezone = (no_saving, has_saving)
|
||||||
|
|
|
@ -57,8 +57,8 @@ from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
|
||||||
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
|
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
|
||||||
errorcode
|
errorcode
|
||||||
|
|
||||||
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
|
_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
|
||||||
EBADF))
|
EBADF})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
socket_map
|
socket_map
|
||||||
|
@ -220,7 +220,7 @@ class dispatcher:
|
||||||
connecting = False
|
connecting = False
|
||||||
closing = False
|
closing = False
|
||||||
addr = None
|
addr = None
|
||||||
ignore_log_types = frozenset(['warning'])
|
ignore_log_types = frozenset({'warning'})
|
||||||
|
|
||||||
def __init__(self, sock=None, map=None):
|
def __init__(self, sock=None, map=None):
|
||||||
if map is None:
|
if map is None:
|
||||||
|
|
|
@ -1088,7 +1088,7 @@ class _BaseV4:
|
||||||
_DECIMAL_DIGITS = frozenset('0123456789')
|
_DECIMAL_DIGITS = frozenset('0123456789')
|
||||||
|
|
||||||
# the valid octets for host and netmasks. only useful for IPv4.
|
# 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
|
_max_prefixlen = IPV4LENGTH
|
||||||
# There are only a handful of valid v4 netmasks, so we cache them all
|
# There are only a handful of valid v4 netmasks, so we cache them all
|
||||||
|
|
|
@ -1230,8 +1230,8 @@ class MH(Mailbox):
|
||||||
class Babyl(_singlefileMailbox):
|
class Babyl(_singlefileMailbox):
|
||||||
"""An Rmail-style Babyl mailbox."""
|
"""An Rmail-style Babyl mailbox."""
|
||||||
|
|
||||||
_special_labels = frozenset(('unseen', 'deleted', 'filed', 'answered',
|
_special_labels = frozenset({'unseen', 'deleted', 'filed', 'answered',
|
||||||
'forwarded', 'edited', 'resent'))
|
'forwarded', 'edited', 'resent'})
|
||||||
|
|
||||||
def __init__(self, path, factory=None, create=True):
|
def __init__(self, path, factory=None, create=True):
|
||||||
"""Initialize a Babyl mailbox."""
|
"""Initialize a Babyl mailbox."""
|
||||||
|
|
|
@ -22,10 +22,10 @@ if _sre.CODESIZE == 2:
|
||||||
else:
|
else:
|
||||||
MAXCODE = 0xFFFFFFFF
|
MAXCODE = 0xFFFFFFFF
|
||||||
|
|
||||||
_LITERAL_CODES = set([LITERAL, NOT_LITERAL])
|
_LITERAL_CODES = {LITERAL, NOT_LITERAL}
|
||||||
_REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT])
|
_REPEATING_CODES = {REPEAT, MIN_REPEAT, MAX_REPEAT}
|
||||||
_SUCCESS_CODES = set([SUCCESS, FAILURE])
|
_SUCCESS_CODES = {SUCCESS, FAILURE}
|
||||||
_ASSERT_CODES = set([ASSERT, ASSERT_NOT])
|
_ASSERT_CODES = {ASSERT, ASSERT_NOT}
|
||||||
|
|
||||||
def _compile(code, pattern, flags):
|
def _compile(code, pattern, flags):
|
||||||
# internal: compile a (sub)pattern
|
# internal: compile a (sub)pattern
|
||||||
|
|
|
@ -25,8 +25,8 @@ HEXDIGITS = frozenset("0123456789abcdefABCDEF")
|
||||||
|
|
||||||
WHITESPACE = frozenset(" \t\n\r\v\f")
|
WHITESPACE = frozenset(" \t\n\r\v\f")
|
||||||
|
|
||||||
_REPEATCODES = frozenset((MIN_REPEAT, MAX_REPEAT))
|
_REPEATCODES = frozenset({MIN_REPEAT, MAX_REPEAT})
|
||||||
_UNITCODES = frozenset((ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY))
|
_UNITCODES = frozenset({ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY})
|
||||||
|
|
||||||
ESCAPES = {
|
ESCAPES = {
|
||||||
r"\a": (LITERAL, ord("\a")),
|
r"\a": (LITERAL, ord("\a")),
|
||||||
|
|
|
@ -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
|
# 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])
|
# 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.
|
# 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)
|
n, d = _exact_ratio(start)
|
||||||
partials = {d: n} # map {denominator: sum of numerators}
|
partials = {d: n} # map {denominator: sum of numerators}
|
||||||
# Micro-optimizations.
|
# Micro-optimizations.
|
||||||
|
@ -168,7 +168,7 @@ def _sum(data, start=0):
|
||||||
assert allowed_types.pop() is int
|
assert allowed_types.pop() is int
|
||||||
T = int
|
T = int
|
||||||
else:
|
else:
|
||||||
T = (allowed_types - set([int])).pop()
|
T = (allowed_types - {int}).pop()
|
||||||
if None in partials:
|
if None in partials:
|
||||||
assert issubclass(T, (float, Decimal))
|
assert issubclass(T, (float, Decimal))
|
||||||
assert not math.isfinite(partials[None])
|
assert not math.isfinite(partials[None])
|
||||||
|
|
|
@ -33,8 +33,7 @@ __all__ = [
|
||||||
# See the EBNF at the top of the file to understand the logical connection
|
# See the EBNF at the top of the file to understand the logical connection
|
||||||
# between the various node types.
|
# between the various node types.
|
||||||
|
|
||||||
builtin_types = set(
|
builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton'}
|
||||||
['identifier', 'string', 'bytes', 'int', 'object', 'singleton'])
|
|
||||||
|
|
||||||
class AST:
|
class AST:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue