Skip to content

Commit

Permalink
Remove dependency to six module
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Vallet committed May 25, 2020
1 parent 90fff86 commit 64c5a36
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 35 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cached-property
Django>=1.8
Django>=2.2
enum-compat
six
3 changes: 0 additions & 3 deletions test_project/generic/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import six
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models


@six.python_2_unicode_compatible
class ModelA(models.Model):
name = models.CharField(max_length=64)

def __str__(self):
return self.name


@six.python_2_unicode_compatible
class ModelB(models.Model):
name = models.CharField(max_length=64)
a = models.ForeignKey(
Expand Down
3 changes: 0 additions & 3 deletions test_project/many_to_many/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import six
from django.db import models


@six.python_2_unicode_compatible
class Publication(models.Model):
title = models.CharField(max_length=30)

Expand All @@ -13,7 +11,6 @@ class Meta:
ordering = ("title",)


@six.python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication, related_name="articles")
Expand Down
3 changes: 0 additions & 3 deletions test_project/many_to_one/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import six
from django.db import models


@six.python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Expand All @@ -12,7 +10,6 @@ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)


@six.python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
Expand Down
4 changes: 0 additions & 4 deletions test_project/one_to_one/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import six
from django.db import models


@six.python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
Expand All @@ -11,7 +9,6 @@ def __str__(self):
return "%s the place" % self.name


@six.python_2_unicode_compatible
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True, on_delete=models.CASCADE)
serves_hot_dogs = models.BooleanField(default=False)
Expand All @@ -21,7 +18,6 @@ def __str__(self):
return "%s the restaurant" % self.place.name


@six.python_2_unicode_compatible
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
Expand Down
9 changes: 4 additions & 5 deletions tests/backends/test_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import six
from alchemy_mock.comparison import ExpressionMatcher
from sqlalchemy import func
from sqlalchemy.orm import joinedload
Expand Down Expand Up @@ -31,7 +30,7 @@ def test_empty(self, alchemy_db):
alchemy_db.query(Place), context={"context": "here"}
)

assert "WHERE 0 = 1" in six.text_type(backend.empty())
assert "WHERE 0 = 1" in str(backend.empty())

def test_get_model(self, alchemy_db):
backend = SQLAlchemyFilterBackend(alchemy_db.query(Place))
Expand All @@ -54,7 +53,7 @@ def test_filter(self, alchemy_db):

filtered = backend.filter()

sql = six.text_type(filtered)
sql = str(filtered)
# eagerloads via outerjoin
assert "LEFT OUTER JOIN one_to_one_restaurant" not in sql
assert "LEFT OUTER JOIN one_to_one_waiter" not in sql
Expand All @@ -74,7 +73,7 @@ def test_filter_already_selectinload(self, alchemy_db):

filtered = backend.filter()

sql = six.text_type(filtered)
sql = str(filtered)
# eagerloads via outerjoin
assert "LEFT OUTER JOIN one_to_one_restaurant" in sql
assert "LEFT OUTER JOIN one_to_one_waiter" not in sql
Expand All @@ -94,7 +93,7 @@ def test_filter_already_eagerloaded(self, alchemy_db):

filtered = backend.filter()

sql = six.text_type(filtered)
sql = str(filtered)
# eagerloads via outerjoin
assert "LEFT OUTER JOIN one_to_one_restaurant" in sql
assert "LEFT OUTER JOIN one_to_one_waiter" in sql
Expand Down
3 changes: 1 addition & 2 deletions url_filter/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import abc

import six
from cached_property import cached_property


class BaseFilterBackend(six.with_metaclass(abc.ABCMeta, object)):
class BaseFilterBackend(metaclass=abc.ABCMeta):
"""
Base filter backend from which all other backends must subclass.
Expand Down
8 changes: 1 addition & 7 deletions url_filter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
from functools import wraps

import six
from cached_property import cached_property
from django import forms
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -38,7 +37,7 @@
)


class BaseFilter(six.with_metaclass(abc.ABCMeta, object)):
class BaseFilter(metaclass=abc.ABCMeta):
"""
Base class to be used for defining both filters and filtersets.
Expand Down Expand Up @@ -72,11 +71,6 @@ def __init__(self, source=None, *args, **kwargs):
self.name = None
self.is_bound = False

def __repr__(self):
data = self.repr()
data = data if six.PY3 else data.encode("utf-8")
return data

@abc.abstractmethod
def repr(self, prefix=""):
"""
Expand Down
6 changes: 3 additions & 3 deletions url_filter/filtersets/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import abc
import functools
import re
from collections import defaultdict
from copy import deepcopy

import six
from cached_property import cached_property
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
Expand Down Expand Up @@ -88,7 +88,7 @@ def __new__(cls, name, bases, attrs):
return new_class


class FilterSet(six.with_metaclass(FilterSetMeta, BaseFilter)):
class FilterSet(BaseFilter, metaclass=FilterSetMeta):
"""
Main user-facing classes to use filtersets.
Expand Down Expand Up @@ -395,7 +395,7 @@ def _generate_lookup_configs(self):
for value in values:
yield LookupConfig(
key,
six.moves.reduce(
functools.reduce(
lambda a, b: {b: a},
(key.replace("!", "").split(LOOKUP_SEP) + [value])[::-1],
),
Expand Down
5 changes: 2 additions & 3 deletions url_filter/filtersets/plain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date, datetime, time
from decimal import Decimal

import six
from django import forms

from ..backends.plain import PlainFilterBackend
Expand All @@ -13,8 +12,8 @@

DATA_TYPES_MAPPING = SubClassDict(
{
six.string_types: forms.CharField(),
six.integer_types: forms.IntegerField(),
str: forms.CharField(),
int: forms.IntegerField(),
bool: forms.BooleanField(required=False),
float: forms.FloatField(),
Decimal: forms.DecimalField(),
Expand Down

0 comments on commit 64c5a36

Please sign in to comment.