Skip to content

Commit

Permalink
More ruff fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Jul 3, 2024
1 parent 8b6f538 commit 0819dd9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions django_unicorn/cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def cache_full_tree(component: "django_unicorn.views.UnicornView"):
cache = caches[get_cache_alias()]

with CacheableComponent(root) as caching:
for component in caching.components():
cache.set(component.component_cache_key, component)
for _component in caching.components():
cache.set(_component.component_cache_key, _component)


def restore_from_cache(component_cache_key: str, request: HttpRequest = None) -> "django_unicorn.views.UnicornView":
Expand All @@ -117,14 +117,14 @@ def restore_from_cache(component_cache_key: str, request: HttpRequest = None) ->

if cached_component:
roots = {}
root: "django_unicorn.views.UnicornView" = cached_component
root: django_unicorn.views.UnicornView = cached_component
roots[root.component_cache_key] = root

while root.parent:
root = cache.get(root.parent.component_cache_key)
roots[root.component_cache_key] = root

to_traverse: List["django_unicorn.views.UnicornView"] = []
to_traverse: List[django_unicorn.views.UnicornView] = []
to_traverse.append(root)

while to_traverse:
Expand Down
6 changes: 3 additions & 3 deletions django_unicorn/management/commands/startunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def create_nested_directories(self, paths: Dict[str, Path], nested_path: str) ->
component_path = paths["components"]
template_path = paths["templates"]

for nested_path in nested_paths:
component_path /= nested_path
template_path /= nested_path
for _nested_path in nested_paths:
component_path /= _nested_path
template_path /= _nested_path

if not component_path.exists():
component_path.mkdir()
Expand Down
18 changes: 9 additions & 9 deletions django_unicorn/typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,36 @@ def cast_value(type_hint, value):
if type(None) in type_hints and value is None:
return value

for type_hint in type_hints:
if type_hint == type(None):
for _type_hint in type_hints:
if _type_hint == type(None):
continue

caster = CASTERS.get(type_hint)
caster = CASTERS.get(_type_hint)

if caster:
try:
value = caster(value)
break
except TypeError:
if (type_hint is datetime or type_hint is date) and (isinstance(value, (float, int))):
if (_type_hint is datetime or _type_hint is date) and (isinstance(value, (float, int))):
try:
value = datetime.fromtimestamp(value, tz=timezone.utc)

if type_hint is date:
if _type_hint is date:
value = value.date()

break
except ValueError:
pass
else:
if issubclass(type_hint, Model):
if issubclass(_type_hint, Model):
continue

if _check_pydantic(type_hint) or is_dataclass(type_hint):
value = type_hint(**value)
if _check_pydantic(_type_hint) or is_dataclass(_type_hint):
value = _type_hint(**value)
break

value = type_hint(value)
value = _type_hint(value)
break

return value
Expand Down
2 changes: 1 addition & 1 deletion tests/call_method_parser/test_parse_kwarg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def test_kwargs_raise_unparseable_value():
with pytest.raises(ValueError) as e:
parse_kwarg("test=some_context_variable", raise_if_unparseable=True)

assert e.type == ValueError
assert e.type is ValueError
2 changes: 1 addition & 1 deletion tests/components/test_get_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_get_locations_apps_setting_invalid(settings, cache_clear): # noqa: ARG
with pytest.raises(AssertionError) as e:
get_locations("hello-world")

assert e.type == AssertionError
assert e.type is AssertionError
settings.UNICORN["APPS"] = ("unicorn",)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_get_morpher_settings(settings):
with pytest.raises(AssertionError) as e:
get_morpher_settings()

assert e.type == AssertionError
assert e.type is AssertionError
assert e.exconly() == "AssertionError: Unknown morpher name: blob"

del settings.UNICORN["MORPHER"]
3 changes: 0 additions & 3 deletions tests/views/fake_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ def mount(self):
print(self.not_a_valid_attribute) # noqa: T201


global count_updating
count_updating = 0

global count_updated
count_updated = 0


Expand Down
4 changes: 2 additions & 2 deletions tests/views/test_is_component_field_model_or_unicorn_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_type_hint():

assert actual
assert component.model is not None
assert type(component.model) == Flavor
assert type(component.model) is Flavor


def test_model_instance():
Expand All @@ -28,4 +28,4 @@ def test_model_instance():

assert actual
assert component.model is not None
assert type(component.model) == Flavor
assert type(component.model) is Flavor

0 comments on commit 0819dd9

Please sign in to comment.