These features have been available since Python 2.7.
This change was made with a version of pyupgrade modified to perform
only this change, then postprocessed with black.
ax_attrs = set(ax_attrs)
required = [] # type: List[str]
if "name" in ax_attrs:
- ax_attrs -= set(["name", "firstname", "fullname", "lastname"])
+ ax_attrs -= {"name", "firstname", "fullname", "lastname"}
required += ["firstname", "fullname", "lastname"]
args.update(
{
"client_secret": client_secret,
}
- fields = set(
- ["id", "name", "first_name", "last_name", "locale", "picture", "link"]
- )
+ fields = {"id", "name", "first_name", "last_name", "locale", "picture", "link"}
if extra_fields:
fields.update(extra_fields)
"PUT": pycurl.UPLOAD,
"HEAD": pycurl.NOBODY,
}
- custom_methods = set(["DELETE", "OPTIONS", "PATCH"])
+ custom_methods = {"DELETE", "OPTIONS", "PATCH"}
for o in curl_options.values():
curl.setopt(o, False)
if request.method in curl_options:
.. versionadded:: 3.1
"""
- return set(opt.group_name for opt in self._options.values())
+ return {opt.group_name for opt in self._options.values()}
def group_dict(self, group: str) -> Dict[str, Any]:
"""The names and values of options in a group.
class _HTTPConnection(httputil.HTTPMessageDelegate):
- _SUPPORTED_METHODS = set(
- ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
- )
+ _SUPPORTED_METHODS = {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}
def __init__(
self,
# Intermediate ("else", "elif", etc) blocks
intermediate_blocks = {
- "else": set(["if", "for", "while", "try"]),
- "elif": set(["if"]),
- "except": set(["try"]),
- "finally": set(["try"]),
+ "else": {"if", "for", "while", "try"},
+ "elif": {"if"},
+ "except": {"try"},
+ "finally": {"try"},
}
allowed_parents = intermediate_blocks.get(operator)
if allowed_parents is not None:
elif operator in ("break", "continue"):
if not in_loop:
reader.raise_parse_error(
- "%s outside %s block" % (operator, set(["for", "while"]))
+ "%s outside %s block" % (operator, {"for", "while"})
)
body.chunks.append(_Statement(contents, line))
continue
def test_iter(self):
options = self._sample_options()
# OptionParsers always define 'help'.
- self.assertEqual(set(["a", "b", "help"]), set(iter(options)))
+ self.assertEqual({"a", "b", "help"}, set(iter(options)))
def test_getitem(self):
options = self._sample_options()
frame = sys._getframe(0)
this_file = frame.f_code.co_filename
- self.assertEqual(set(["b_group", "", this_file]), options.groups())
+ self.assertEqual({"b_group", "", this_file}, options.groups())
b_group_dict = options.group_dict("b_group")
self.assertEqual({"b": 2}, b_group_dict)
def run(self, test):
result = super().run(test)
if result.skipped:
- skip_reasons = set(reason for (test, reason) in result.skipped)
+ skip_reasons = {reason for (test, reason) in result.skipped}
self.stream.write( # type: ignore
textwrap.fill(
"Some tests were skipped because: %s"
self.triggers.popleft()()
self.triggers.popleft()()
self.wait(condition=lambda: (len(self.triggers) == 2 and len(seen) == 2))
- self.assertEqual(set(seen), set([0, 1]))
+ self.assertEqual(set(seen), {0, 1})
self.assertEqual(len(client.queue), 0)
# Finish all the pending requests
self.triggers.popleft()()
self.triggers.popleft()()
self.wait(condition=lambda: len(seen) == 4)
- self.assertEqual(set(seen), set([0, 1, 2, 3]))
+ self.assertEqual(set(seen), {0, 1, 2, 3})
self.assertEqual(len(self.triggers), 0)
@gen_test
# The port used here doesn't matter, but some systems require it
# to be non-zero if we do not also pass AI_PASSIVE.
addrinfo = self.io_loop.run_sync(lambda: Resolver().resolve("localhost", 80))
- families = set(addr[0] for addr in addrinfo)
+ families = {addr[0] for addr in addrinfo}
if socket.AF_INET6 not in families:
self.skipTest("localhost does not resolve to ipv6")
# make sure the uncompressed file still has the correct type
response = self.fetch("/static/sample.xml")
self.assertIn(
- response.headers.get("Content-Type"), set(("text/xml", "application/xml"))
+ response.headers.get("Content-Type"), {"text/xml", "application/xml"}
)
def test_static_url(self):
def test_refresh_token(self):
token = self.xsrf_token
- tokens_seen = set([token])
+ tokens_seen = {token}
# A user's token is stable over time. Refreshing the page in one tab
# might update the cookie while an older tab still has the old cookie
# in its DOM. Simulate this scenario by passing a constant token
# server is only running on ipv4. Test for this edge case and skip
# the test if it happens.
addrinfo = yield Resolver().resolve("localhost", port)
- families = set(addr[0] for addr in addrinfo)
+ families = {addr[0] for addr in addrinfo}
if socket.AF_INET not in families:
self.skipTest("localhost does not resolve to ipv4")
return
# Whitelist of compressible mime types (in addition to any types
# beginning with "text/").
- CONTENT_TYPES = set(
- [
- "application/javascript",
- "application/x-javascript",
- "application/xml",
- "application/atom+xml",
- "application/json",
- "application/xhtml+xml",
- "image/svg+xml",
- ]
- )
+ CONTENT_TYPES = {
+ "application/javascript",
+ "application/x-javascript",
+ "application/xml",
+ "application/atom+xml",
+ "application/json",
+ "application/xhtml+xml",
+ "image/svg+xml",
+ }
# Python's GzipFile defaults to level 9, while most other gzip
# tools (including gzip itself) default to 6, which is probably a
# better CPU/size tradeoff.
compression_options: Optional[Dict[str, Any]] = None,
) -> None:
# TODO: handle invalid parameters gracefully
- allowed_keys = set(
- [
- "server_no_context_takeover",
- "client_no_context_takeover",
- "server_max_window_bits",
- "client_max_window_bits",
- ]
- )
+ allowed_keys = {
+ "server_no_context_takeover",
+ "client_no_context_takeover",
+ "server_max_window_bits",
+ "client_max_window_bits",
+ }
for key in agreed_parameters:
if key not in allowed_keys:
raise ValueError("unsupported compression parameter %r" % key)
status_code_str, reason = data["status"].split(" ", 1)
status_code = int(status_code_str)
headers = data["headers"] # type: List[Tuple[str, str]]
- header_set = set(k.lower() for (k, v) in headers)
+ header_set = {k.lower() for (k, v) in headers}
body = escape.utf8(body)
if status_code != 304:
if "content-length" not in header_set: