Skip to content
Merged
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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [
"3.6",
"3.7",
"3.8",
"3.9",
]
es-version: [7.0.0, 7.10.0]

steps:
Expand Down
17 changes: 8 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
Expand Down Expand Up @@ -62,8 +61,8 @@
master_doc = "index"

# General information about the project.
project = u"Elasticsearch DSL"
copyright = u"%d, Elasticsearch B.V" % datetime.datetime.now().year
project = "Elasticsearch DSL"
copyright = "%d, Elasticsearch B.V" % datetime.datetime.now().year

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -216,8 +215,8 @@
(
"index",
"Elasticsearch-dsl.tex",
u"Elasticsearch DSL Documentation",
u"Elasticsearch B.V",
"Elasticsearch DSL Documentation",
"Elasticsearch B.V",
"manual",
),
]
Expand Down Expand Up @@ -251,8 +250,8 @@
(
"index",
"elasticsearch-dsl",
u"Elasticsearch DSL Documentation",
[u"Elasticsearch B.V"],
"Elasticsearch DSL Documentation",
["Elasticsearch B.V"],
1,
)
]
Expand All @@ -270,8 +269,8 @@
(
"index",
"Elasticsearch",
u"Elasticsearch Documentation",
u"Elasticsearch B.V",
"Elasticsearch Documentation",
"Elasticsearch B.V",
"Elasticsearch",
"One line description of project.",
"Miscellaneous",
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from .utils import AttrDict, AttrList, DslBase
from .wrappers import Range

VERSION = (7, 2, 0)
VERSION = (8, 0, 0)
__version__ = VERSION
__versionstr__ = ".".join(map(str, VERSION))
__all__ = [
Expand Down
17 changes: 7 additions & 10 deletions elasticsearch_dsl/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
# specific language governing permissions and limitations
# under the License.

try:
import collections.abc as collections_abc # only works on python 3.3+
except ImportError:
import collections as collections_abc
import collections.abc

from .response.aggs import AggResponse, BucketData, FieldBucketData, TopHitsData
from .utils import DslBase
Expand All @@ -34,7 +31,7 @@ def A(name_or_agg, filter=None, **params):
params["filter"] = filter

# {"terms": {"field": "tags"}, "aggs": {...}}
if isinstance(name_or_agg, collections_abc.Mapping):
if isinstance(name_or_agg, collections.abc.Mapping):
if params:
raise ValueError("A() cannot accept parameters when passing in a dict.")
# copy to avoid modifying in-place
Expand Down Expand Up @@ -79,7 +76,7 @@ def __contains__(self, key):
return False

def to_dict(self):
d = super(Agg, self).to_dict()
d = super().to_dict()
if "meta" in d[self.name]:
d["meta"] = d[self.name].pop("meta")
return d
Expand All @@ -88,7 +85,7 @@ def result(self, search, data):
return AggResponse(self, search, data)


class AggBase(object):
class AggBase:
_param_defs = {
"aggs": {"type": "agg", "hash": True},
}
Expand Down Expand Up @@ -139,7 +136,7 @@ def result(self, search, data):

class Bucket(AggBase, Agg):
def __init__(self, **params):
super(Bucket, self).__init__(**params)
super().__init__(**params)
# remember self for chaining
self._base = self

Expand All @@ -160,10 +157,10 @@ class Filter(Bucket):
def __init__(self, filter=None, **params):
if filter is not None:
params["filter"] = filter
super(Filter, self).__init__(**params)
super().__init__(**params)

def to_dict(self):
d = super(Filter, self).to_dict()
d = super().to_dict()
d[self.name].update(d[self.name].pop("filter", {}))
return d

Expand Down
22 changes: 10 additions & 12 deletions elasticsearch_dsl/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
# specific language governing permissions and limitations
# under the License.

import six

from .connections import get_connection
from .utils import AttrDict, DslBase, merge

__all__ = ["tokenizer", "analyzer", "char_filter", "token_filter", "normalizer"]


class AnalysisBase(object):
class AnalysisBase:
@classmethod
def _type_shortcut(cls, name_or_instance, type=None, **kwargs):
if isinstance(name_or_instance, cls):
if type or kwargs:
raise ValueError("%s() cannot accept parameters." % cls.__name__)
raise ValueError(f"{cls.__name__}() cannot accept parameters.")
return name_or_instance

if not (type or kwargs):
Expand All @@ -39,20 +37,20 @@ def _type_shortcut(cls, name_or_instance, type=None, **kwargs):
)


class CustomAnalysis(object):
class CustomAnalysis:
name = "custom"

def __init__(self, filter_name, builtin_type="custom", **kwargs):
self._builtin_type = builtin_type
self._name = filter_name
super(CustomAnalysis, self).__init__(**kwargs)
super().__init__(**kwargs)

def to_dict(self):
# only name to present in lists
return self._name

def get_definition(self):
d = super(CustomAnalysis, self).to_dict()
d = super().to_dict()
d = d.pop(self.name)
d["type"] = self._builtin_type
return d
Expand Down Expand Up @@ -92,12 +90,12 @@ def get_analysis_definition(self):
return out


class BuiltinAnalysis(object):
class BuiltinAnalysis:
name = "builtin"

def __init__(self, name):
self._name = name
super(BuiltinAnalysis, self).__init__()
super().__init__()

def to_dict(self):
# only name to present in lists
Expand Down Expand Up @@ -148,7 +146,7 @@ def simulate(self, text, using="default", explain=False, attributes=None):
sec_def = definition.get(section, {})
sec_names = analyzer_def[section]

if isinstance(sec_names, six.string_types):
if isinstance(sec_names, str):
body[section] = sec_def.get(sec_names, sec_names)
else:
body[section] = [
Expand Down Expand Up @@ -213,7 +211,7 @@ def get_definition(self):
if "filters" in d:
d["filters"] = [
# comma delimited string given by user
fs if isinstance(fs, six.string_types) else
fs if isinstance(fs, str) else
# list of strings or TokenFilter objects
", ".join(f.to_dict() if hasattr(f, "to_dict") else f for f in fs)
for fs in self.filters
Expand All @@ -227,7 +225,7 @@ def get_analysis_definition(self):
fs = {}
d = {"filter": fs}
for filters in self.filters:
if isinstance(filters, six.string_types):
if isinstance(filters, str):
continue
fs.update(
{
Expand Down
9 changes: 4 additions & 5 deletions elasticsearch_dsl/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
# under the License.

from elasticsearch import Elasticsearch
from six import string_types

from .serializer import serializer


class Connections(object):
class Connections:
"""
Class responsible for holding connections to different clusters. Used as a
singleton in this module.
Expand Down Expand Up @@ -73,7 +72,7 @@ def remove_connection(self, alias):
errors += 1

if errors == 2:
raise KeyError("There is no connection with alias %r." % alias)
raise KeyError(f"There is no connection with alias {alias!r}.")

def create_connection(self, alias="default", **kwargs):
"""
Expand All @@ -95,7 +94,7 @@ def get_connection(self, alias="default"):
"""
# do not check isinstance(Elasticsearch) so that people can wrap their
# clients
if not isinstance(alias, string_types):
if not isinstance(alias, str):
return alias

# connection already established
Expand All @@ -109,7 +108,7 @@ def get_connection(self, alias="default"):
return self.create_connection(alias, **self._kwargs[alias])
except KeyError:
# no connection and no kwargs to set one up
raise KeyError("There is no connection with alias %r." % alias)
raise KeyError(f"There is no connection with alias {alias!r}.")


connections = Connections()
Expand Down
Loading