Skip to content

Commit

Permalink
refactor: fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JuroOravec committed May 9, 2024
1 parent ef7a600 commit 754162f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/django_components/attributes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Initial implementation based on attributes.py from django-web-components
# See https://github.com/Xzya/django-web-components/blob/b43eb0c832837db939a6f8c1980334b0adfdd6e4/django_web_components/templatetags/components.py
# And https://github.com/Xzya/django-web-components/blob/b43eb0c832837db939a6f8c1980334b0adfdd6e4/django_web_components/attributes.py
# See https://github.com/Xzya/django-web-components/blob/b43eb0c832837db939a6f8c1980334b0adfdd6e4/django_web_components/templatetags/components.py # noqa: E501
# And https://github.com/Xzya/django-web-components/blob/b43eb0c832837db939a6f8c1980334b0adfdd6e4/django_web_components/attributes.py # noqa: E501

import re
from typing import Any, Dict, List, Mapping, Tuple
Expand Down Expand Up @@ -116,7 +116,7 @@ def parse_attributes(
# For those kwargs where keyword starts with 'add::', we assume that these
# keys should be concatenated. For the rest, we don't do any special processing.
if raw_attr.startswith(_ATTR_ADD_PREFIX):
attr = raw_attr[len(_ATTR_ADD_PREFIX) :]
attr = raw_attr[len(_ATTR_ADD_PREFIX):]
append_attrs.append((attr, value))
else:
default_attrs.append((raw_attr, value))
Expand Down
8 changes: 4 additions & 4 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_does_not_escape_special_characters_if_safe_string(self):

def test_result_is_safe_string(self):
result = attributes_to_string({"foo": mark_safe("'bar'")})
self.assertTrue(type(result) == SafeString)
self.assertTrue(isinstance(result, SafeString))

def test_attribute_with_no_value(self):
self.assertEqual(
Expand Down Expand Up @@ -82,7 +82,7 @@ class AttrsComponent(component.Component):
<div {% html_attrs attrs class="override-me" add::class="added_class" add::class="another-class" data-id=123 %}>
content
</div>
"""
""" # noqa: E501

def get_context_data(self, *args, attrs):
return {"attrs": attrs}
Expand All @@ -91,7 +91,7 @@ def get_context_data(self, *args, attrs):
{% load component_tags %}
{% component "test" attrs::@click.stop="dispatch('click_event')" attrs::x-data="{hello: 'world'}" attrs::class=class_var %}
{% endcomponent %}
"""
""" # noqa: E501
template = Template(template_str)
rendered = template.render(Context({"class_var": "padding-top-8"}))
self.assertHTMLEqual(
Expand All @@ -100,6 +100,6 @@ def get_context_data(self, *args, attrs):
<div @click.stop="dispatch('click_event')" x-data="{hello: 'world'}" class="padding-top-8 added_class another-class" data-id=123>
content
</div>
""",
""", # noqa: E501
)
self.assertNotIn("override-me", rendered)
4 changes: 2 additions & 2 deletions tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ def get_context_data(self, *args, attrs, my_dict):
{% load component_tags %}
{% component "test" attrs::@click.stop="dispatch('click_event')" attrs::x-data="{hello: 'world'}" attrs::class=class_var my_dict::one=2 %}
{% endcomponent %}
"""
""" # noqa: E501
template = Template(template_str)
rendered = template.render(Context({"class_var": "padding-top-8"}))
self.assertHTMLEqual(
Expand All @@ -1017,5 +1017,5 @@ def get_context_data(self, *args, attrs, my_dict):
attrs: {'@click.stop': "dispatch('click_event')", 'x-data': "{hello: 'world'}", 'class': 'padding-top-8'}
my_dict: {'one': 2}
</div>
""",
""", # noqa: E501
)

0 comments on commit 754162f

Please sign in to comment.