ruff: Fix SIM108 Use ternary operator instead of if
-else
-block.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
2aa36f90fb
commit
b009dcd7d3
9 changed files with 30 additions and 77 deletions
10
tools/deploy
10
tools/deploy
|
@ -181,10 +181,7 @@ def prepare(options: argparse.Namespace) -> None:
|
|||
def log(options: argparse.Namespace) -> None:
|
||||
check_common_options(options)
|
||||
headers = {"key": options.token}
|
||||
if options.lines:
|
||||
lines = options.lines
|
||||
else:
|
||||
lines = None
|
||||
lines = options.lines
|
||||
payload = {"name": options.botname, "lines": lines}
|
||||
url = urllib.parse.urljoin(options.server, "bots/logs/" + options.botname)
|
||||
response = requests.get(url, json=payload, headers=headers)
|
||||
|
@ -209,10 +206,7 @@ def delete(options: argparse.Namespace) -> None:
|
|||
def list_bots(options: argparse.Namespace) -> None:
|
||||
check_common_options(options)
|
||||
headers = {"key": options.token}
|
||||
if options.format:
|
||||
pretty_print = True
|
||||
else:
|
||||
pretty_print = False
|
||||
pretty_print = options.format
|
||||
url = urllib.parse.urljoin(options.server, "bots/list")
|
||||
response = requests.get(url, headers=headers)
|
||||
result = handle_common_response(
|
||||
|
|
|
@ -77,13 +77,10 @@ the Python version this command is executed with."""
|
|||
else:
|
||||
print("Virtualenv already exists.")
|
||||
|
||||
if os.path.isdir(os.path.join(venv_dir, "Scripts")):
|
||||
# POSIX compatibility layer and Linux environment emulation for Windows
|
||||
# venv uses /Scripts instead of /bin on Windows cmd and Power Shell.
|
||||
# Read https://docs.python.org/3/library/venv.html
|
||||
venv_exec_dir = "Scripts"
|
||||
else:
|
||||
venv_exec_dir = "bin"
|
||||
# POSIX compatibility layer and Linux environment emulation for Windows
|
||||
# venv uses /Scripts instead of /bin on Windows cmd and Power Shell.
|
||||
# Read https://docs.python.org/3/library/venv.html
|
||||
venv_exec_dir = "Scripts" if os.path.isdir(os.path.join(venv_dir, "Scripts")) else "bin"
|
||||
|
||||
# On OS X, ensure we use the virtualenv version of the python binary for
|
||||
# future subprocesses instead of the version that this script was launched with. See
|
||||
|
|
|
@ -452,10 +452,7 @@ option does not affect login credentials.""".replace("\n", " "),
|
|||
zulipToJabber.set_jabber_client(xmpp)
|
||||
|
||||
xmpp.process(block=False)
|
||||
if options.mode == "public":
|
||||
event_types = ["stream"]
|
||||
else:
|
||||
event_types = ["message", "subscription"]
|
||||
event_types = ["stream"] if options.mode == "public" else ["message", "subscription"]
|
||||
|
||||
try:
|
||||
logging.info("Connecting to Zulip.")
|
||||
|
|
|
@ -31,11 +31,8 @@ P4_WEB: Optional[str] = None
|
|||
# * subject "change_root"
|
||||
def commit_notice_destination(path: str, changelist: int) -> Optional[Dict[str, str]]:
|
||||
dirs = path.split("/")
|
||||
if len(dirs) >= 4 and dirs[3] not in ("*", "..."):
|
||||
directory = dirs[3]
|
||||
else:
|
||||
# No subdirectory, so just use "depot"
|
||||
directory = dirs[2]
|
||||
# If no subdirectory, just use "depot"
|
||||
directory = dirs[3] if len(dirs) >= 4 and dirs[3] not in ("*", "...") else dirs[2]
|
||||
|
||||
if directory not in ["evil-master-plan", "my-super-secret-repository"]:
|
||||
return dict(stream=f"{directory}-commits", subject=path)
|
||||
|
|
|
@ -181,15 +181,9 @@ elif opts.twitter_name:
|
|||
else:
|
||||
statuses = api.GetUserTimeline(screen_name=opts.twitter_name, since_id=since_id)
|
||||
|
||||
if opts.excluded_terms:
|
||||
excluded_terms = opts.excluded_terms.split(",")
|
||||
else:
|
||||
excluded_terms = []
|
||||
excluded_terms = opts.excluded_terms.split(",") if opts.excluded_terms else []
|
||||
|
||||
if opts.excluded_users:
|
||||
excluded_users = opts.excluded_users.split(",")
|
||||
else:
|
||||
excluded_users = []
|
||||
excluded_users = opts.excluded_users.split(",") if opts.excluded_users else []
|
||||
|
||||
for status in statuses[::-1][: opts.limit_tweets]:
|
||||
# Check if the tweet is from an excluded user
|
||||
|
|
|
@ -36,9 +36,6 @@ assert sys.version_info >= (3, 6)
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# In newer versions, the 'json' attribute is a function, not a property
|
||||
requests_json_is_function = callable(requests.Response.json)
|
||||
|
||||
API_VERSTRING = "v1/"
|
||||
|
||||
# An optional parameter to `move_topic` and `update_message` actions
|
||||
|
@ -571,14 +568,11 @@ class Client:
|
|||
if files is None:
|
||||
files = []
|
||||
|
||||
if longpolling:
|
||||
# When long-polling, set timeout to 90 sec as a balance
|
||||
# between a low traffic rate and a still reasonable latency
|
||||
# time in case of a connection failure.
|
||||
request_timeout = 90.0
|
||||
else:
|
||||
# Otherwise, 15s should be plenty of time.
|
||||
request_timeout = 15.0 if not timeout else timeout
|
||||
# When long-polling, set timeout to 90 sec as a balance
|
||||
# between a low traffic rate and a still reasonable latency
|
||||
# time in case of a connection failure.
|
||||
# Otherwise, 15s should be plenty of time.
|
||||
request_timeout = 90.0 if longpolling else timeout or 15.0
|
||||
|
||||
request = {}
|
||||
req_files = []
|
||||
|
@ -630,10 +624,7 @@ class Client:
|
|||
|
||||
while True:
|
||||
try:
|
||||
if method == "GET":
|
||||
kwarg = "params"
|
||||
else:
|
||||
kwarg = "data"
|
||||
kwarg = "params" if method == "GET" else "data"
|
||||
|
||||
kwargs = {kwarg: query_state["request"]}
|
||||
|
||||
|
@ -689,22 +680,17 @@ class Client:
|
|||
raise
|
||||
|
||||
try:
|
||||
if requests_json_is_function:
|
||||
json_result = res.json()
|
||||
else:
|
||||
json_result = res.json
|
||||
json_result = res.json()
|
||||
except Exception:
|
||||
json_result = None
|
||||
end_error_retry(False)
|
||||
return {
|
||||
"msg": "Unexpected error from the server",
|
||||
"result": "http-error",
|
||||
"status_code": res.status_code,
|
||||
}
|
||||
|
||||
if json_result is not None:
|
||||
end_error_retry(True)
|
||||
return json_result
|
||||
end_error_retry(False)
|
||||
return {
|
||||
"msg": "Unexpected error from the server",
|
||||
"result": "http-error",
|
||||
"status_code": res.status_code,
|
||||
}
|
||||
end_error_retry(True)
|
||||
return json_result
|
||||
|
||||
def call_endpoint(
|
||||
self,
|
||||
|
|
|
@ -113,10 +113,7 @@ def syntax_help(cmd_name: str) -> str:
|
|||
commands = get_commands()
|
||||
f, arg_names = commands[cmd_name]
|
||||
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
||||
if arg_syntax:
|
||||
cmd = cmd_name + " " + arg_syntax
|
||||
else:
|
||||
cmd = cmd_name
|
||||
cmd = cmd_name + " " + arg_syntax if arg_syntax else cmd_name
|
||||
return f"syntax: {cmd}"
|
||||
|
||||
|
||||
|
@ -207,10 +204,7 @@ def dbx_read(client: Any, fn: str) -> str:
|
|||
|
||||
|
||||
def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str:
|
||||
if folder is None:
|
||||
folder = ""
|
||||
else:
|
||||
folder = "/" + folder
|
||||
folder = "" if folder is None else "/" + folder
|
||||
if max_results is None:
|
||||
max_results = "20"
|
||||
try:
|
||||
|
|
|
@ -303,10 +303,7 @@ def display_game(topic_name, merels_storage):
|
|||
|
||||
response = ""
|
||||
|
||||
if data.take_mode == 1:
|
||||
take = "Yes"
|
||||
else:
|
||||
take = "No"
|
||||
take = "Yes" if data.take_mode == 1 else "No"
|
||||
|
||||
response += interface.graph_grid(data.grid()) + "\n"
|
||||
response += f"""Phase {data.get_phase()}. Take mode: {take}.
|
||||
|
|
|
@ -166,10 +166,7 @@ def syntax_help(cmd_name: str) -> str:
|
|||
commands = get_commands()
|
||||
f, arg_names = commands[cmd_name]
|
||||
arg_syntax = " ".join("<" + a + ">" for a in arg_names)
|
||||
if arg_syntax:
|
||||
cmd = cmd_name + " " + arg_syntax
|
||||
else:
|
||||
cmd = cmd_name
|
||||
cmd = cmd_name + " " + arg_syntax if arg_syntax else cmd_name
|
||||
return f"syntax: {cmd}"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue