refactor: ruff - underscore unused vars (#1372)

This commit is contained in:
Juro Oravec 2025-09-10 22:06:47 +02:00 committed by GitHub
parent f100cc1836
commit c5354baf4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 35 additions and 35 deletions

View file

@ -846,7 +846,7 @@ def _extract_property_docstrings(cls: Type) -> Dict[str, str]:
- The function assumes that the class is defined at the global scope (module level)
and that the body is indented with 4 spaces.
"""
lines, start_line_index = inspect.getsourcelines(cls)
lines, _start_line_index = inspect.getsourcelines(cls)
attrs_lines: List[str] = []
ignore = True
for line in lines:

View file

@ -155,7 +155,7 @@ class ComponentListCommand(ListCommand):
data: List[Dict[str, Any]] = []
for component in components:
full_name = get_import_path(component)
module, module_name, module_file_path = get_module_info(component)
_module, _module_name, module_file_path = get_module_info(component)
# Make paths relative to CWD
if module_file_path:

View file

@ -837,7 +837,7 @@ def _resolve_component_relative_files(
component_name = comp_cls.__qualname__
# Get the full path of the file where the component was defined
module, module_name, module_file_path = get_module_info(comp_cls)
_module, module_name, module_file_path = get_module_info(comp_cls)
if not module_file_path:
logger.debug(
f"Could not resolve the path to the file for component '{component_name}'."

View file

@ -233,7 +233,7 @@ class ComponentFormatter(TagFormatterABC):
return f"end{self.tag}"
def parse(self, tokens: List[str]) -> TagResult:
tag, *args = tokens
_tag, *args = tokens
if not args:
raise TemplateSyntaxError(f"{self.__class__.__name__}: Component tag did not receive tag name")

View file

@ -54,7 +54,7 @@ class GenIdPatcher:
def mock_gen_id(*_args: Any, **_kwargs: Any) -> str:
self._gen_id_count += 1
return hex(self._gen_id_count)[2:]
return f"{self._gen_id_count:x}"
self._gen_id_patch = patch("django_components.util.misc.generate", side_effect=mock_gen_id)
self._gen_id_patch.start()

View file

@ -3962,7 +3962,7 @@ form_template_str: types.django_html = """
class FormData(NamedTuple):
type: Literal["table", "paragraph", "ul", None] = None
type: Optional[Literal["table", "paragraph", "ul"]] = None
editable: bool = True
method: str = "post"
# Submit btn

View file

@ -3702,7 +3702,7 @@ class Form(Component):
self,
/,
*,
type: Literal["table", "paragraph", "ul", None] = None, # noqa: A002
type: Optional[Literal["table", "paragraph", "ul"]] = None, # noqa: A002
editable: bool = True,
method: str = "post",
# Submit btn

View file

@ -1483,7 +1483,7 @@ class TestComponentHook:
def on_render(self, context: Context, template: Optional[Template]):
calls.append("slotted__on_render_pre")
html, error = yield template.render(context) # type: ignore[union-attr]
_html, _error = yield template.render(context) # type: ignore[union-attr]
calls.append("slotted__on_render_post")
@ -1516,7 +1516,7 @@ class TestComponentHook:
if template is None:
yield None
else:
html, error = yield template.render(context)
_html, _error = yield template.render(context)
calls.append("inner__on_render_post")
@ -1550,7 +1550,7 @@ class TestComponentHook:
def on_render(self, context: Context, template: Optional[Template]):
calls.append("middle__on_render_pre")
html, error = yield template.render(context) # type: ignore[union-attr]
_html, _error = yield template.render(context) # type: ignore[union-attr]
calls.append("middle__on_render_post")
@ -1582,7 +1582,7 @@ class TestComponentHook:
def on_render(self, context: Context, template: Optional[Template]):
calls.append("outer__on_render_pre")
html, error = yield template.render(context) # type: ignore[union-attr]
_html, _error = yield template.render(context) # type: ignore[union-attr]
calls.append("outer__on_render_post")
@ -1702,7 +1702,7 @@ class TestComponentHook:
# Check we can modify entries set by other methods
context["from_on_before__edited1"] = context["from_on_before"] + " (on_render)"
html, error = yield template.render(context)
_html, _error = yield template.render(context)
context["from_on_render_post"] = "3"
@ -1754,7 +1754,7 @@ class TestComponentHook:
def on_render(self, context: Context, template: Template):
template.nodelist.append(TextNode("\n---\nFROM_ON_RENDER_PRE"))
html, error = yield template.render(context)
_html, _error = yield template.render(context)
template.nodelist.append(TextNode("\n---\nFROM_ON_RENDER_POST"))
@ -1802,7 +1802,7 @@ class TestComponentHook:
"""
def on_render(self, context: Context, template: Template):
html, error = yield template.render(context)
_html, error = yield template.render(context)
raise error from None # Re-raise original error
@ -1851,7 +1851,7 @@ class TestComponentHook:
)
def test_result_interception(
self,
template: Literal["simple", "broken", None],
template: Optional[Literal["simple", "broken"]],
action: Literal["return_none", "no_return", "raise_error", "return_html"],
method: Literal["on_render", "on_render_after"],
):
@ -1888,7 +1888,7 @@ class TestComponentHook:
if template is None:
yield None
else:
html, error = yield template.render(context)
_html, _error = yield template.render(context)
return None # noqa: PLR1711
elif action == "no_return":
@ -1898,7 +1898,7 @@ class TestComponentHook:
if template is None:
yield None
else:
html, error = yield template.render(context)
_html, _error = yield template.render(context)
elif action == "raise_error":
@ -1907,7 +1907,7 @@ class TestComponentHook:
if template is None:
yield None
else:
html, error = yield template.render(context)
_html, _error = yield template.render(context)
raise ValueError("ERROR_FROM_ON_RENDER")
elif action == "return_html":
@ -1917,7 +1917,7 @@ class TestComponentHook:
if template is None:
yield None
else:
html, error = yield template.render(context)
_html, _error = yield template.render(context)
return "HTML_FROM_ON_RENDER"
else:

View file

@ -32,7 +32,7 @@ class NoopNode(Node):
def noop(parser: Parser, token: Token):
tag, raw_expr = token.split_contents()
_tag, raw_expr = token.split_contents()
expr = parser.compile_filter(raw_expr)
return NoopNode(expr)

View file

@ -1252,7 +1252,7 @@ class TestTagParser:
TemplateSyntaxError,
match=re.escape("Unexpected colon"),
):
_, attrs = parse_tag("component data={ key:: key }", None)
_, _attrs = parse_tag("component data={ key:: key }", None)
def test_dict_spread(self):
_, attrs = parse_tag("component data={ **spread }", None)
@ -1378,7 +1378,7 @@ class TestTagParser:
TemplateSyntaxError,
match=re.escape("Filter argument (':arg') must follow a filter ('|filter')"),
):
_, attrs = parse_tag('component data={"key"|filter:"arg": "value"}', None)
_, _attrs = parse_tag('component data={"key"|filter:"arg": "value"}', None)
def test_list_simple(self):
_, attrs = parse_tag("component data=[1, 2, 3]", None)
@ -2217,14 +2217,14 @@ class TestTagParser:
TemplateSyntaxError,
match=re.escape("Spread syntax cannot be used in place of a dictionary key"),
):
_, attrs = parse_tag("component data={**spread|abc: 123 }", None)
_, _attrs = parse_tag("component data={**spread|abc: 123 }", None)
def test_spread_in_filter_position(self):
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax cannot be used inside of a filter"),
):
_, attrs = parse_tag("component data=val|...spread|abc }", None)
_, _attrs = parse_tag("component data=val|...spread|abc }", None)
def test_spread_whitespace(self):
# NOTE: Separating `...` from its variable is NOT valid, and will result in error.
@ -2324,49 +2324,49 @@ class TestTagParser:
TemplateSyntaxError,
match=re.escape("Spread syntax '*' found outside of a list"),
):
_, attrs = parse_tag('component dict={"a": "b", *my_attr}', None)
_, _attrs = parse_tag('component dict={"a": "b", *my_attr}', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '...' found in dict. It must be used on tag attributes only"),
):
_, attrs = parse_tag('component dict={"a": "b", ...my_attr}', None)
_, _attrs = parse_tag('component dict={"a": "b", ...my_attr}', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '**' found outside of a dictionary"),
):
_, attrs = parse_tag('component list=["a", "b", **my_list]', None)
_, _attrs = parse_tag('component list=["a", "b", **my_list]', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '...' found in list. It must be used on tag attributes only"),
):
_, attrs = parse_tag('component list=["a", "b", ...my_list]', None)
_, _attrs = parse_tag('component list=["a", "b", ...my_list]', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '*' found outside of a list"),
):
_, attrs = parse_tag("component *attrs", None)
_, _attrs = parse_tag("component *attrs", None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '**' found outside of a dictionary"),
):
_, attrs = parse_tag("component **attrs", None)
_, _attrs = parse_tag("component **attrs", None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '*' found outside of a list"),
):
_, attrs = parse_tag("component key=*attrs", None)
_, _attrs = parse_tag("component key=*attrs", None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '**' found outside of a dictionary"),
):
_, attrs = parse_tag("component key=**attrs", None)
_, _attrs = parse_tag("component key=**attrs", None)
# Test that one cannot do `key=...{"a": "b"}`
def test_spread_onto_key(self):
@ -2374,19 +2374,19 @@ class TestTagParser:
TemplateSyntaxError,
match=re.escape("Spread syntax '...' cannot follow a key ('key=...attrs')"),
):
_, attrs = parse_tag('component key=...{"a": "b"}', None)
_, _attrs = parse_tag('component key=...{"a": "b"}', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '...' cannot follow a key ('key=...attrs')"),
):
_, attrs = parse_tag('component key=...["a", "b"]', None)
_, _attrs = parse_tag('component key=...["a", "b"]', None)
with pytest.raises(
TemplateSyntaxError,
match=re.escape("Spread syntax '...' cannot follow a key ('key=...attrs')"),
):
_, attrs = parse_tag("component key=...attrs", None)
_, _attrs = parse_tag("component key=...attrs", None)
def test_spread_dict_literal_nested(self):
_, attrs = parse_tag('component { **{"key": val2}, "key": val1 }', None)