From 613840ebcf303e84048d48ace37fb001c1afe687 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 6 May 2023 16:12:32 +0100 Subject: Apply fixes for ruff linting Co-authored-by: wookie184 Co-authored-by: Amrou Bellalouna --- bot/exts/core/internal_eval/_helpers.py | 10 +++++----- bot/exts/core/internal_eval/_internal_eval.py | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'bot/exts/core/internal_eval') diff --git a/bot/exts/core/internal_eval/_helpers.py b/bot/exts/core/internal_eval/_helpers.py index 5b2f8f5d..34ef7fef 100644 --- a/bot/exts/core/internal_eval/_helpers.py +++ b/bot/exts/core/internal_eval/_helpers.py @@ -8,7 +8,7 @@ import logging import sys import traceback import types -from typing import Any, Optional, Union +from typing import Any log = logging.getLogger(__name__) @@ -120,7 +120,7 @@ class EvalContext: log.trace(f"Updating {self._locals} with {locals_}") self._locals.update(locals_) - def prepare_eval(self, code: str) -> Optional[str]: + def prepare_eval(self, code: str) -> str | None: """Prepare an evaluation by processing the code and setting up the context.""" self.code = code @@ -149,7 +149,7 @@ class EvalContext: compiled_code = compile(self.eval_tree, filename=INTERNAL_EVAL_FRAMENAME, mode="exec") log.trace("Executing the compiled code with the desired namespace environment") - exec(compiled_code, self.locals) # noqa: B102,S102 + exec(compiled_code, self.locals) # noqa: S102 log.trace("Awaiting the created evaluation wrapper coroutine.") await self.function() @@ -212,7 +212,7 @@ class CaptureLastExpression(ast.NodeTransformer): self.tree = tree self.last_node = list(ast.iter_child_nodes(tree))[-1] - def visit_Expr(self, node: ast.Expr) -> Union[ast.Expr, ast.Assign]: # noqa: N802 + def visit_Expr(self, node: ast.Expr) -> ast.Expr | ast.Assign: # noqa: N802 """ Replace the Expr node that is last child node of Module with an assignment. @@ -230,7 +230,7 @@ class CaptureLastExpression(ast.NodeTransformer): right_hand_side = list(ast.iter_child_nodes(node))[0] assignment = ast.Assign( - targets=[ast.Name(id='_value_last_expression', ctx=ast.Store())], + targets=[ast.Name(id="_value_last_expression", ctx=ast.Store())], value=right_hand_side, lineno=node.lineno, col_offset=0, diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 2daf8ef9..f5188c1f 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -1,7 +1,6 @@ import logging import re import textwrap -from typing import Optional import discord from discord.ext import commands @@ -84,7 +83,7 @@ class InternalEval(commands.Cog): return shortened_output - async def _upload_output(self, output: str) -> Optional[str]: + async def _upload_output(self, output: str) -> str | None: """Upload `internal eval` output to our pastebin and return the url.""" data = self.shorten_output(output, max_length=MAX_LENGTH) try: -- cgit v1.2.3