Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.16
rev: v0.16.1
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion src/django_ltree/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class DjangoLtreeConfig(AppConfig):

def ready(self):
from . import checks as checks
from . import lookups as lookups
from . import functions as functions
from . import lookups as lookups
10 changes: 4 additions & 6 deletions src/django_ltree/fields.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from collections import UserList
from collections.abc import Iterable

from django import forms
from django.core.validators import RegexValidator
from django.db.models.fields import TextField
from django.forms.widgets import TextInput

from collections.abc import Iterable

path_label_validator = RegexValidator(
r"^(?P<root>[a-zA-Z0-9_-]+)(?:\.[a-zA-Z0-9_-]+)*$",
"A label is a sequence of alphanumeric characters and underscores separated by dots.",
Expand All @@ -23,7 +23,7 @@ def __init__(self, value):
elif isinstance(value, Iterable):
value = [str(v) for v in value]
else:
raise ValueError("Invalid value: {!r} for path".format(value))
raise ValueError(f"Invalid value: {value!r} for path")

super().__init__(initlist=value)

Expand Down Expand Up @@ -89,9 +89,7 @@ def get_prep_value(self, value):
return str(PathValue(value))

def to_python(self, value):
if value is None:
return value
elif isinstance(value, PathValue):
if value is None or isinstance(value, PathValue):
return value

return PathValue(value)
Expand Down
5 changes: 2 additions & 3 deletions src/django_ltree/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.db.models import Transform
from django.db.models import fields
from .fields import PathField
from django.db.models import Transform, fields

from .fields import PathField

__all__ = ("NLevel",)

Expand Down
4 changes: 3 additions & 1 deletion src/django_ltree/managers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.db import models
from typing import TYPE_CHECKING

from django.db import models

from django_ltree.paths import PathGenerator

from .querysets import TreeQuerySet
Expand Down
3 changes: 2 additions & 1 deletion src/django_ltree/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from typing import Any

from django.db import models

from .fields import PathField, PathValue
from .managers import TreeManager

Expand Down
2 changes: 1 addition & 1 deletion src/django_ltree/paths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import string
import math
import string
from itertools import product

from .fields import PathValue
Expand Down
4 changes: 2 additions & 2 deletions src/django_ltree/querysets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models

from typing import TYPE_CHECKING

from django.db import models

if TYPE_CHECKING:
from .models import TreeModel

Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import django
from django.conf import settings

Expand Down
3 changes: 1 addition & 2 deletions tests/taxonomy/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-09-11 12:31
from __future__ import unicode_literals

from django.db import migrations, models

import django_ltree.fields


Expand Down
2 changes: 1 addition & 1 deletion tests/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def test_label_generation():
def test_automatic_name_creation():
from taxonomy.models import Taxonomy

for i in range(0, 1000):
for i in range(1000):
Taxonomy.objects.create_child(name=i)
2 changes: 0 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest

from taxonomy.models import Taxonomy


TEST_DATA = [
{"name": "Bacteria"},
{"name": "Plantae"},
Expand Down
5 changes: 2 additions & 3 deletions tests/test_path_field.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pytest

from django.core.exceptions import ValidationError
from django_ltree.fields import PathValue

from taxonomy.models import Taxonomy

from django_ltree.fields import PathValue


@pytest.mark.parametrize(
["path", "valid"],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_register.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django_ltree import functions, lookups
from django_ltree.fields import PathField
from django_ltree import lookups, functions


def test_registered_lookups():
Expand Down