Skip to content

Commit

Permalink
Use new syntax in stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Jun 12, 2024
1 parent 1ef5255 commit e7e6601
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 68 deletions.
6 changes: 3 additions & 3 deletions Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ class FloatOperation(DecimalException, TypeError):

_current_context_var = contextvars.ContextVar('decimal_context')

_context_attributes = frozenset(
['prec', 'Emin', 'Emax', 'capitals', 'clamp', 'rounding', 'flags', 'traps']
)
_context_attributes = {{
'prec', 'Emin', 'Emax', 'capitals', 'clamp', 'rounding', 'flags', 'traps'
}}

def getcontext():
"""Returns this thread's context.
Expand Down
4 changes: 2 additions & 2 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def __calc_timezone(self):
pass
self.tzname = time.tzname
self.daylight = time.daylight
no_saving = frozenset({"utc", "gmt", self.tzname[0].lower()})
no_saving = {{"utc", "gmt", self.tzname[0].lower()}}
if self.daylight:
has_saving = frozenset({self.tzname[1].lower()})
has_saving = {{self.tzname[1].lower()}}
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
Expand Down
2 changes: 1 addition & 1 deletion Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ def visit_UnaryOp(self, node):
"**": _Precedence.POWER,
}

binop_rassoc = frozenset(("**",))
binop_rassoc = {{"**"}}
def visit_BinOp(self, node):
operator = self.binop[node.op.__class__.__name__]
operator_precedence = self.binop_precedence[operator]
Expand Down
4 changes: 2 additions & 2 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __repr__(self):

# Atomic immutable types which don't require any recursive handling and for which deepcopy
# returns the same object. We can provide a fast-path for these types in asdict and astuple.
_ATOMIC_TYPES = frozenset({
_ATOMIC_TYPES = {{
# Common JSON Serializable types
types.NoneType,
bool,
Expand All @@ -242,7 +242,7 @@ def __repr__(self):
type,
range,
property,
})
}}


class InitVar:
Expand Down
2 changes: 1 addition & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ def request(self, method, url, body=None, headers={}, *,

def _send_request(self, method, url, body, headers, encode_chunked):
# Honor explicitly requested Host: and Accept-Encoding: headers.
header_names = frozenset(k.lower() for k in headers)
header_names = {{k.lower() for k in headers}}
skips = {}
if 'host' in header_names:
skips['skip_host'] = 1
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/hyperparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_surrounding_brackets(self, openers='([{', mustclose=False):

# the set of built-in identifiers which are also keywords,
# i.e. keyword.iskeyword() returns True for them
_ID_KEYWORDS = frozenset({"True", "False", "None"})
_ID_KEYWORDS = {{"True", "False", "None"}}

@classmethod
def _eat_identifier(cls, str, limit, pos):
Expand Down
4 changes: 2 additions & 2 deletions Lib/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,8 @@ def _dump_sequences(self, message, key):
class Babyl(_singlefileMailbox):
"""An Rmail-style Babyl mailbox."""

_special_labels = frozenset({'unseen', 'deleted', 'filed', 'answered',
'forwarded', 'edited', 'resent'})
_special_labels = {{'unseen', 'deleted', 'filed', 'answered', 'forwarded',
'edited', 'resent'}}

def __init__(self, path, factory=None, create=True):
"""Initialize a Babyl mailbox."""
Expand Down
3 changes: 1 addition & 2 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,7 @@ def PipeClient(address):
# of the opening challenge or length of the returned digest as a signal as
# to which protocol the other end supports.

_ALLOWED_DIGESTS = frozenset(
{b'md5', b'sha256', b'sha384', b'sha3_256', b'sha3_384'})
_ALLOWED_DIGESTS = {{b'md5', b'sha256', b'sha384', b'sha3_256', b'sha3_384'}}
_MAX_DIGEST_LEN = max(len(_) for _ in _ALLOWED_DIGESTS)

# Old hmac-md5 only server versions from Python <=3.11 sent a message of this
Expand Down
14 changes: 7 additions & 7 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ def ismount(path):
return False


_reserved_chars = frozenset(
{chr(i) for i in range(32)} |
{'"', '*', ':', '<', '>', '?', '|', '/', '\\'}
_reserved_chars = (
{{chr(i) for i in range(32)}} |
{{'"', '*', ':', '<', '>', '?', '|', '/', '\\'}}
)

_reserved_names = frozenset(
{'CON', 'PRN', 'AUX', 'NUL', 'CONIN$', 'CONOUT$'} |
{f'COM{c}' for c in '123456789\xb9\xb2\xb3'} |
{f'LPT{c}' for c in '123456789\xb9\xb2\xb3'}
_reserved_names = (
{{'CON', 'PRN', 'AUX', 'NUL', 'CONIN$', 'CONOUT$'}} |
{{f'COM{c}' for c in '123456789\xb9\xb2\xb3'}} |
{{f'LPT{c}' for c in '123456789\xb9\xb2\xb3'}}
)

def isreserved(path):
Expand Down
2 changes: 1 addition & 1 deletion Lib/pickletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def __init__(self, name, code, arg,
of the stack from the topmost markobject onward. For example,
Stack before: ... markobject 1 2 3
Stack after: ... frozenset({1, 2, 3})
Stack after: ... {{1, 2, 3}}
"""),

# Stack manipulation.
Expand Down
3 changes: 1 addition & 2 deletions Lib/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,7 @@ def _safe_repr(self, object, context, maxlevels, level):
rep = repr(object)
return rep, (rep and not rep.startswith('<')), False

_builtin_scalars = frozenset({str, bytes, bytearray, float, complex,
bool, type(None)})
_builtin_scalars = {{str, bytes, bytearray, float, complex, bool, type(None)}}

def _recursion(object):
return ("<Recursion on %s with id=%s>"
Expand Down
4 changes: 2 additions & 2 deletions Lib/re/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

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

_REPEATCODES = frozenset({MIN_REPEAT, MAX_REPEAT, POSSESSIVE_REPEAT})
_UNITCODES = frozenset({ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY})
_REPEATCODES = {{MIN_REPEAT, MAX_REPEAT, POSSESSIVE_REPEAT}}
_UNITCODES = {{ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY}}

ESCAPES = {
r"\a": (LITERAL, ord("\a")),
Expand Down
2 changes: 1 addition & 1 deletion Lib/reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def repr_frozenset(self, x, level):
if not x:
return 'frozenset()'
x = _possibly_sorted(x)
return self._repr_iterable(x, level, 'frozenset({', '})',
return self._repr_iterable(x, level, '{{', '}}',
self.maxfrozenset)

def repr_deque(self, x, level):
Expand Down
52 changes: 26 additions & 26 deletions Lib/test/test_reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def test_container(self):

# Frozensets give up after 6 as well
eq(r(frozenset([])), "frozenset()")
eq(r(frozenset([1])), "frozenset({1})")
eq(r(frozenset([1, 2, 3])), "frozenset({1, 2, 3})")
eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset({1, 2, 3, 4, 5, 6})")
eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset({1, 2, 3, 4, 5, 6, ...})")
eq(r(frozenset([1])), "{{1}}")
eq(r(frozenset([1, 2, 3])), "{{1, 2, 3}}")
eq(r(frozenset([1, 2, 3, 4, 5, 6])), "{{1, 2, 3, 4, 5, 6}}")
eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "{{1, 2, 3, 4, 5, 6, ...}}")

# collections.deque after 6
eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])")
Expand Down Expand Up @@ -142,12 +142,12 @@ def test_set_literal(self):
eq(r({1, 2, 3, 4, 5, 6}), "{1, 2, 3, 4, 5, 6}")
eq(r({1, 2, 3, 4, 5, 6, 7}), "{1, 2, 3, 4, 5, 6, ...}")

def test_frozenset(self):
def test_frozenset_literal(self):
eq = self.assertEqual
eq(r(frozenset({1})), "frozenset({1})")
eq(r(frozenset({1, 2, 3})), "frozenset({1, 2, 3})")
eq(r(frozenset({1, 2, 3, 4, 5, 6})), "frozenset({1, 2, 3, 4, 5, 6})")
eq(r(frozenset({1, 2, 3, 4, 5, 6, 7})), "frozenset({1, 2, 3, 4, 5, 6, ...})")
eq(r({{1}}), "{{1}}")
eq(r({{1, 2, 3}}), "{{1, 2, 3}}")
eq(r({{1, 2, 3, 4, 5, 6}}), "{{1, 2, 3, 4, 5, 6}}")
eq(r({{1, 2, 3, 4, 5, 6, 7}}), "{{1, 2, 3, 4, 5, 6, ...}}")

def test_numbers(self):
eq = self.assertEqual
Expand Down Expand Up @@ -378,7 +378,7 @@ def test_valid_indent(self):
},
'tests': (
(dict(indent=None), '''\
{1: 'two', b'three': [(4.5, 6.7), [{8, 9}, frozenset({10, 11})]]}'''),
{1: 'two', b'three': [(4.5, 6.7), [{8, 9}, {{10, 11}}]]}'''),
(dict(indent=False), '''\
{
1: 'two',
Expand All @@ -392,10 +392,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -412,10 +412,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -432,10 +432,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -452,10 +452,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -472,10 +472,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -500,10 +500,10 @@ def test_valid_indent(self):
8,
9,
},
frozenset({
{{
10,
11,
}),
}},
],
],
}'''),
Expand All @@ -520,10 +520,10 @@ def test_valid_indent(self):
-->-->-->-->8,
-->-->-->-->9,
-->-->-->},
-->-->-->frozenset({
-->-->-->{{
-->-->-->-->10,
-->-->-->-->11,
-->-->-->}),
-->-->-->}},
-->-->],
-->],
}'''),
Expand All @@ -540,10 +540,10 @@ def test_valid_indent(self):
................8,
................9,
............},
............frozenset({
............{{
................10,
................11,
............}),
............}},
........],
....],
}'''),
Expand Down
6 changes: 3 additions & 3 deletions Lib/tomllib/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
)
from ._types import Key, ParseFloat, Pos

ASCII_CTRL = frozenset(chr(i) for i in range(32)) | frozenset(chr(127))
ASCII_CTRL = {{chr(i) for i in range(32)}} | {{chr(127)}}

# Neither of these sets include quotation mark or backslash. They are
# currently handled as separate cases in the parser functions.
ILLEGAL_BASIC_STR_CHARS = ASCII_CTRL - frozenset("\t")
ILLEGAL_BASIC_STR_CHARS = ASCII_CTRL - {{"\t"}}
ILLEGAL_MULTILINE_BASIC_STR_CHARS = ASCII_CTRL - frozenset("\t\n")

ILLEGAL_LITERAL_STR_CHARS = ILLEGAL_BASIC_STR_CHARS
Expand All @@ -32,7 +32,7 @@
ILLEGAL_COMMENT_CHARS = ILLEGAL_BASIC_STR_CHARS

TOML_WS = frozenset(" \t")
TOML_WS_AND_NEWLINE = TOML_WS | frozenset("\n")
TOML_WS_AND_NEWLINE = TOML_WS | {{"\n"}}
BARE_KEY_CHARS = frozenset(string.ascii_letters + string.digits + "-_")
KEY_INITIAL_CHARS = BARE_KEY_CHARS | frozenset("\"'")
HEXDIGIT_CHARS = frozenset(string.hexdigits)
Expand Down
18 changes: 9 additions & 9 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,19 +1878,19 @@ class _TypingEllipsis:
"""Internal placeholder for ... (ellipsis)."""


_TYPING_INTERNALS = frozenset({
_TYPING_INTERNALS = {{
'__parameters__', '__orig_bases__', '__orig_class__',
'_is_protocol', '_is_runtime_protocol', '__protocol_attrs__',
'__non_callable_proto_members__', '__type_params__',
})
}}

_SPECIAL_NAMES = frozenset({
_SPECIAL_NAMES = {{
'__abstractmethods__', '__annotations__', '__dict__', '__doc__',
'__init__', '__module__', '__new__', '__slots__',
'__subclasshook__', '__weakref__', '__class_getitem__',
'__match_args__', '__static_attributes__', '__firstlineno__',
'__annotate__',
})
}}

# These special attributes will be not collected as protocol members.
EXCLUDED_ATTRIBUTES = _TYPING_INTERNALS | _SPECIAL_NAMES | {'_MutableMapping__marker'}
Expand Down Expand Up @@ -2955,11 +2955,11 @@ def _make_nmtuple(name, types, module, defaults = ()):


# attributes prohibited to set in NamedTuple class syntax
_prohibited = frozenset({'__new__', '__init__', '__slots__', '__getnewargs__',
'_fields', '_field_defaults',
'_make', '_replace', '_asdict', '_source'})
_prohibited = {{'__new__', '__init__', '__slots__', '__getnewargs__',
'_fields', '_field_defaults', '_make', '_replace', '_asdict',
'_source'}}

_special = frozenset({'__module__', '__name__', '__annotations__'})
_special = {{'__module__', '__name__', '__annotations__'}}


class NamedTupleMeta(type):
Expand Down Expand Up @@ -3749,7 +3749,7 @@ def get_protocol_members(tp: type, /) -> frozenset[str]:
>>> class P(Protocol):
... def a(self) -> str: ...
... b: int
>>> get_protocol_members(P) == frozenset({'a', 'b'})
>>> get_protocol_members(P) == {{'a', 'b'}}
True
Raise a TypeError for arguments that are not Protocols.
Expand Down
4 changes: 2 additions & 2 deletions Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,11 @@ def _calls_repr(self):


# Denylist for forbidden attribute names in safe mode
_ATTRIB_DENY_LIST = frozenset({
_ATTRIB_DENY_LIST = {{
name.removeprefix("assert_")
for name in dir(NonCallableMock)
if name.startswith("assert_")
})
}}


class _AnyComparer(list):
Expand Down
2 changes: 1 addition & 1 deletion Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def main(args=None):
'to the latest version in PyPI')
parser.add_argument('--without-scm-ignore-files', dest='scm_ignore_files',
action='store_const', const=frozenset(),
default=frozenset(['git']),
default={{'git'}},
help='Skips adding SCM ignore files to the environment '
'directory (Git is supported by default).')
options = parser.parse_args(args)
Expand Down

0 comments on commit e7e6601

Please sign in to comment.