Skip to content

Commit 0184a77

Browse files
review imports for consistency
1 parent 3690105 commit 0184a77

18 files changed

+126
-86
lines changed

elasticsearch_dsl/__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
from . import connections
1919
from .aggs import A
2020
from .analysis import analyzer, char_filter, normalizer, token_filter, tokenizer
21-
from .document import Document, InnerDoc, MetaField
21+
from .document import AsyncDocument, Document
22+
from .document_base import InnerDoc, MetaField
2223
from .exceptions import (
2324
ElasticsearchDslException,
2425
IllegalOperation,
2526
UnknownDslObject,
2627
ValidationException,
2728
)
2829
from .faceted_search import (
30+
AsyncFacetedSearch,
2931
DateHistogramFacet,
3032
Facet,
3133
FacetedResponse,
@@ -76,11 +78,11 @@
7678
construct_field,
7779
)
7880
from .function import SF
79-
from .index import Index, IndexTemplate
80-
from .mapping import Mapping
81+
from .index import AsyncIndex, AsyncIndexTemplate, Index, IndexTemplate
82+
from .mapping import AsyncMapping, Mapping
8183
from .query import Q
82-
from .search import MultiSearch, Search
83-
from .update_by_query import UpdateByQuery
84+
from .search import AsyncMultiSearch, AsyncSearch, MultiSearch, Search
85+
from .update_by_query import AsyncUpdateByQuery, UpdateByQuery
8486
from .utils import AttrDict, AttrList, DslBase
8587
from .wrappers import Range
8688

@@ -89,6 +91,14 @@
8991
__versionstr__ = ".".join(map(str, VERSION))
9092
__all__ = [
9193
"A",
94+
"AsyncDocument",
95+
"AsyncFacetedSearch",
96+
"AsyncIndex",
97+
"AsyncIndexTemplate",
98+
"AsyncMapping",
99+
"AsyncMultiSearch",
100+
"AsyncSearch",
101+
"AsyncUpdateByQuery",
92102
"AttrDict",
93103
"AttrList",
94104
"Binary",

elasticsearch_dsl/_async/document.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from .._async.index import AsyncIndex
2323
from ..async_connections import get_connection
24-
from ..document_base import * # noqa: F401, F403
2524
from ..document_base import DocumentBase, DocumentMeta
2625
from ..exceptions import IllegalOperation
2726
from ..utils import DOC_META_FIELDS, META_FIELDS, merge

elasticsearch_dsl/_sync/document.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from .._sync.index import Index
2323
from ..connections import get_connection
24-
from ..document_base import * # noqa: F401, F403
2524
from ..document_base import DocumentBase, DocumentMeta
2625
from ..exceptions import IllegalOperation
2726
from ..utils import DOC_META_FIELDS, META_FIELDS, merge

elasticsearch_dsl/document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from elasticsearch_dsl._sync.document import Document, InnerDoc, MetaField # noqa: F401
18+
from elasticsearch_dsl._async.document import AsyncDocument # noqa: F401
19+
from elasticsearch_dsl._sync.document import Document # noqa: F401
20+
from elasticsearch_dsl.document_base import InnerDoc, MetaField # noqa: F401

elasticsearch_dsl/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from ._async.index import AsyncIndex, AsyncIndexTemplate # noqa: F401
1819
from ._sync.index import Index, IndexTemplate # noqa: F401

elasticsearch_dsl/mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from elasticsearch_dsl._async.mapping import AsyncMapping # noqa: F401
1819
from elasticsearch_dsl._sync.mapping import Mapping # noqa: F401

elasticsearch_dsl/search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from elasticsearch_dsl._async.search import AsyncMultiSearch, AsyncSearch # noqa: F401
1819
from elasticsearch_dsl._sync.search import MultiSearch, Search # noqa: F401
1920
from elasticsearch_dsl.search_base import Q # noqa: F401

elasticsearch_dsl/update_by_query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from ._async.update_by_query import AsyncUpdateByQuery # noqa: F401
1819
from ._sync.update_by_query import UpdateByQuery # noqa: F401

tests/_async/test_document.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@
2323

2424
from pytest import raises
2525

26-
from elasticsearch_dsl import Index, InnerDoc, Mapping, Range, analyzer, field, utils
27-
from elasticsearch_dsl._async import document
26+
from elasticsearch_dsl import (
27+
AsyncDocument,
28+
Index,
29+
InnerDoc,
30+
Mapping,
31+
MetaField,
32+
Range,
33+
analyzer,
34+
field,
35+
utils,
36+
)
2837
from elasticsearch_dsl.exceptions import IllegalOperation, ValidationException
2938

3039

3140
class MyInner(InnerDoc):
3241
old_field = field.Text()
3342

3443

35-
class MyDoc(document.AsyncDocument):
44+
class MyDoc(AsyncDocument):
3645
title = field.Keyword()
3746
name = field.Text()
3847
created_at = field.Date()
@@ -46,27 +55,27 @@ class Index:
4655
name = "default-index"
4756

4857

49-
class MyDoc2(document.AsyncDocument):
58+
class MyDoc2(AsyncDocument):
5059
extra = field.Long()
5160

5261

5362
class MyMultiSubDoc(MyDoc2, MySubDoc):
5463
pass
5564

5665

57-
class Comment(document.InnerDoc):
66+
class Comment(InnerDoc):
5867
title = field.Text()
5968
tags = field.Keyword(multi=True)
6069

6170

62-
class DocWithNested(document.AsyncDocument):
71+
class DocWithNested(AsyncDocument):
6372
comments = field.Nested(Comment)
6473

6574
class Index:
6675
name = "test-doc-with-nested"
6776

6877

69-
class SimpleCommit(document.AsyncDocument):
78+
class SimpleCommit(AsyncDocument):
7079
files = field.Text(multi=True)
7180

7281
class Index:
@@ -89,36 +98,36 @@ def _deserialize(self, data):
8998
return Secret(codecs.decode(data, "rot_13"))
9099

91100

92-
class SecretDoc(document.AsyncDocument):
101+
class SecretDoc(AsyncDocument):
93102
title = SecretField(index="no")
94103

95104
class Index:
96105
name = "test-secret-doc"
97106

98107

99-
class NestedSecret(document.AsyncDocument):
108+
class NestedSecret(AsyncDocument):
100109
secrets = field.Nested(SecretDoc)
101110

102111
class Index:
103112
name = "test-nested-secret"
104113

105114

106-
class OptionalObjectWithRequiredField(document.AsyncDocument):
115+
class OptionalObjectWithRequiredField(AsyncDocument):
107116
comments = field.Nested(properties={"title": field.Keyword(required=True)})
108117

109118
class Index:
110119
name = "test-required"
111120

112121

113-
class Host(document.AsyncDocument):
122+
class Host(AsyncDocument):
114123
ip = field.Ip()
115124

116125
class Index:
117126
name = "test-host"
118127

119128

120129
def test_range_serializes_properly():
121-
class D(document.AsyncDocument):
130+
class D(AsyncDocument):
122131
lr = field.LongRange()
123132

124133
d = D(lr=Range(lt=42))
@@ -131,7 +140,7 @@ class D(document.AsyncDocument):
131140

132141

133142
def test_range_deserializes_properly():
134-
class D(document.InnerDoc):
143+
class D(InnerDoc):
135144
lr = field.LongRange()
136145

137146
d = D.from_es({"lr": {"lt": 42}}, True)
@@ -147,10 +156,10 @@ def test_resolve_nested():
147156

148157

149158
def test_conflicting_mapping_raises_error_in_index_to_dict():
150-
class A(document.AsyncDocument):
159+
class A(AsyncDocument):
151160
name = field.Text()
152161

153-
class B(document.AsyncDocument):
162+
class B(AsyncDocument):
154163
name = field.Keyword()
155164

156165
i = Index("i")
@@ -173,15 +182,15 @@ def test_matches_uses_index():
173182

174183

175184
def test_matches_with_no_name_always_matches():
176-
class D(document.AsyncDocument):
185+
class D(AsyncDocument):
177186
pass
178187

179188
assert D._matches({})
180189
assert D._matches({"_index": "whatever"})
181190

182191

183192
def test_matches_accepts_wildcards():
184-
class MyDoc(document.AsyncDocument):
193+
class MyDoc(AsyncDocument):
185194
class Index:
186195
name = "my-*"
187196

@@ -339,14 +348,14 @@ def test_meta_is_accessible_even_on_empty_doc():
339348

340349

341350
def test_meta_field_mapping():
342-
class User(document.AsyncDocument):
351+
class User(AsyncDocument):
343352
username = field.Text()
344353

345354
class Meta:
346-
all = document.MetaField(enabled=False)
347-
_index = document.MetaField(enabled=True)
348-
dynamic = document.MetaField("strict")
349-
dynamic_templates = document.MetaField([42])
355+
all = MetaField(enabled=False)
356+
_index = MetaField(enabled=True)
357+
dynamic = MetaField("strict")
358+
dynamic_templates = MetaField([42])
350359

351360
assert {
352361
"properties": {"username": {"type": "text"}},
@@ -358,7 +367,7 @@ class Meta:
358367

359368

360369
def test_multi_value_fields():
361-
class Blog(document.AsyncDocument):
370+
class Blog(AsyncDocument):
362371
tags = field.Keyword(multi=True)
363372

364373
b = Blog()
@@ -369,7 +378,7 @@ class Blog(document.AsyncDocument):
369378

370379

371380
def test_docs_with_properties():
372-
class User(document.AsyncDocument):
381+
class User(AsyncDocument):
373382
pwd_hash = field.Text()
374383

375384
def check_password(self, pwd):
@@ -441,7 +450,7 @@ def test_to_dict_ignores_empty_collections():
441450

442451

443452
def test_declarative_mapping_definition():
444-
assert issubclass(MyDoc, document.AsyncDocument)
453+
assert issubclass(MyDoc, AsyncDocument)
445454
assert hasattr(MyDoc, "_doc_type")
446455
assert {
447456
"properties": {
@@ -454,7 +463,7 @@ def test_declarative_mapping_definition():
454463

455464

456465
def test_you_can_supply_own_mapping_instance():
457-
class MyD(document.AsyncDocument):
466+
class MyD(AsyncDocument):
458467
title = field.Text()
459468

460469
class Meta:
@@ -497,7 +506,7 @@ def test_invalid_date_will_raise_exception():
497506

498507
def test_document_inheritance():
499508
assert issubclass(MySubDoc, MyDoc)
500-
assert issubclass(MySubDoc, document.AsyncDocument)
509+
assert issubclass(MySubDoc, AsyncDocument)
501510
assert hasattr(MySubDoc, "_doc_type")
502511
assert {
503512
"properties": {
@@ -510,7 +519,7 @@ def test_document_inheritance():
510519

511520

512521
def test_child_class_can_override_parent():
513-
class A(document.AsyncDocument):
522+
class A(AsyncDocument):
514523
o = field.Object(dynamic=False, properties={"a": field.Text()})
515524

516525
class B(A):
@@ -540,7 +549,7 @@ def test_meta_fields_are_stored_in_meta_and_ignored_by_to_dict():
540549
def test_index_inheritance():
541550
assert issubclass(MyMultiSubDoc, MySubDoc)
542551
assert issubclass(MyMultiSubDoc, MyDoc2)
543-
assert issubclass(MyMultiSubDoc, document.AsyncDocument)
552+
assert issubclass(MyMultiSubDoc, AsyncDocument)
544553
assert hasattr(MyMultiSubDoc, "_doc_type")
545554
assert hasattr(MyMultiSubDoc, "_index")
546555
assert {
@@ -601,7 +610,7 @@ def test_from_es_respects_underscored_non_meta_fields():
601610
},
602611
}
603612

604-
class Company(document.AsyncDocument):
613+
class Company(AsyncDocument):
605614
class Index:
606615
name = "test-company"
607616

tests/_async/test_index.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020

2121
from pytest import raises
2222

23-
from elasticsearch_dsl import Date, Text, analyzer
24-
from elasticsearch_dsl._async.document import AsyncDocument
25-
from elasticsearch_dsl._async.index import AsyncIndex, AsyncIndexTemplate
23+
from elasticsearch_dsl import (
24+
AsyncDocument,
25+
AsyncIndex,
26+
AsyncIndexTemplate,
27+
Date,
28+
Text,
29+
analyzer,
30+
)
2631

2732

2833
class Post(AsyncDocument):

tests/_async/test_update_by_query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
from copy import deepcopy
1919

20-
from elasticsearch_dsl import Q
21-
from elasticsearch_dsl._async.update_by_query import AsyncUpdateByQuery
20+
from elasticsearch_dsl import AsyncUpdateByQuery, Q
2221
from elasticsearch_dsl.response import UpdateByQueryResponse
2322

2423

0 commit comments

Comments
 (0)