Skip to content

Commit 222bf2d

Browse files
committed
chore(ndb): add format session and modernize lint and blacken to use Ruff
1 parent 5accbb4 commit 222bf2d

60 files changed

Lines changed: 393 additions & 438 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/google-cloud-ndb/google/cloud/ndb/__init__.py

Lines changed: 106 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -25,110 +25,115 @@
2525

2626
__version__: str = version.__version__
2727

28+
from google.cloud.ndb._datastore_api import EVENTUAL, EVENTUAL_CONSISTENCY, STRONG
29+
from google.cloud.ndb._datastore_query import Cursor, QueryIterator
30+
from google.cloud.ndb._transaction import (
31+
in_transaction,
32+
non_transactional,
33+
transaction,
34+
transaction_async,
35+
transactional,
36+
transactional_async,
37+
transactional_tasklet,
38+
)
2839
from google.cloud.ndb.client import Client
29-
from google.cloud.ndb.context import AutoBatcher
30-
from google.cloud.ndb.context import Context
31-
from google.cloud.ndb.context import ContextOptions
32-
from google.cloud.ndb.context import get_context
33-
from google.cloud.ndb.context import get_toplevel_context
34-
from google.cloud.ndb.context import TransactionOptions
35-
from google.cloud.ndb._datastore_api import EVENTUAL
36-
from google.cloud.ndb._datastore_api import EVENTUAL_CONSISTENCY
37-
from google.cloud.ndb._datastore_api import STRONG
38-
from google.cloud.ndb._datastore_query import Cursor
39-
from google.cloud.ndb._datastore_query import QueryIterator
40-
from google.cloud.ndb.global_cache import GlobalCache
41-
from google.cloud.ndb.global_cache import MemcacheCache
42-
from google.cloud.ndb.global_cache import RedisCache
40+
from google.cloud.ndb.context import (
41+
AutoBatcher,
42+
Context,
43+
ContextOptions,
44+
TransactionOptions,
45+
get_context,
46+
get_toplevel_context,
47+
)
48+
from google.cloud.ndb.global_cache import GlobalCache, MemcacheCache, RedisCache
4349
from google.cloud.ndb.key import Key
44-
from google.cloud.ndb.model import BlobKey
45-
from google.cloud.ndb.model import BlobKeyProperty
46-
from google.cloud.ndb.model import BlobProperty
47-
from google.cloud.ndb.model import BooleanProperty
48-
from google.cloud.ndb.model import ComputedProperty
49-
from google.cloud.ndb.model import ComputedPropertyError
50-
from google.cloud.ndb.model import DateProperty
51-
from google.cloud.ndb.model import DateTimeProperty
52-
from google.cloud.ndb.model import delete_multi
53-
from google.cloud.ndb.model import delete_multi_async
54-
from google.cloud.ndb.model import Expando
55-
from google.cloud.ndb.model import FloatProperty
56-
from google.cloud.ndb.model import GenericProperty
57-
from google.cloud.ndb.model import GeoPt
58-
from google.cloud.ndb.model import GeoPtProperty
59-
from google.cloud.ndb.model import get_indexes
60-
from google.cloud.ndb.model import get_indexes_async
61-
from google.cloud.ndb.model import get_multi
62-
from google.cloud.ndb.model import get_multi_async
63-
from google.cloud.ndb.model import Index
64-
from google.cloud.ndb.model import IndexProperty
65-
from google.cloud.ndb.model import IndexState
66-
from google.cloud.ndb.model import IntegerProperty
67-
from google.cloud.ndb.model import InvalidPropertyError
68-
from google.cloud.ndb.model import BadProjectionError
69-
from google.cloud.ndb.model import JsonProperty
70-
from google.cloud.ndb.model import KeyProperty
71-
from google.cloud.ndb.model import KindError
72-
from google.cloud.ndb.model import LocalStructuredProperty
73-
from google.cloud.ndb.model import make_connection
74-
from google.cloud.ndb.model import MetaModel
75-
from google.cloud.ndb.model import Model
76-
from google.cloud.ndb.model import ModelAdapter
77-
from google.cloud.ndb.model import ModelAttribute
78-
from google.cloud.ndb.model import ModelKey
79-
from google.cloud.ndb.model import PickleProperty
80-
from google.cloud.ndb.model import Property
81-
from google.cloud.ndb.model import put_multi
82-
from google.cloud.ndb.model import put_multi_async
83-
from google.cloud.ndb.model import ReadonlyPropertyError
84-
from google.cloud.ndb.model import Rollback
85-
from google.cloud.ndb.model import StringProperty
86-
from google.cloud.ndb.model import StructuredProperty
87-
from google.cloud.ndb.model import TextProperty
88-
from google.cloud.ndb.model import TimeProperty
89-
from google.cloud.ndb.model import UnprojectedPropertyError
90-
from google.cloud.ndb.model import User
91-
from google.cloud.ndb.model import UserNotFoundError
92-
from google.cloud.ndb.model import UserProperty
50+
from google.cloud.ndb.model import (
51+
BadProjectionError,
52+
BlobKey,
53+
BlobKeyProperty,
54+
BlobProperty,
55+
BooleanProperty,
56+
ComputedProperty,
57+
ComputedPropertyError,
58+
DateProperty,
59+
DateTimeProperty,
60+
Expando,
61+
FloatProperty,
62+
GenericProperty,
63+
GeoPt,
64+
GeoPtProperty,
65+
Index,
66+
IndexProperty,
67+
IndexState,
68+
IntegerProperty,
69+
InvalidPropertyError,
70+
JsonProperty,
71+
KeyProperty,
72+
KindError,
73+
LocalStructuredProperty,
74+
MetaModel,
75+
Model,
76+
ModelAdapter,
77+
ModelAttribute,
78+
ModelKey,
79+
PickleProperty,
80+
Property,
81+
ReadonlyPropertyError,
82+
Rollback,
83+
StringProperty,
84+
StructuredProperty,
85+
TextProperty,
86+
TimeProperty,
87+
UnprojectedPropertyError,
88+
User,
89+
UserNotFoundError,
90+
UserProperty,
91+
delete_multi,
92+
delete_multi_async,
93+
get_indexes,
94+
get_indexes_async,
95+
get_multi,
96+
get_multi_async,
97+
make_connection,
98+
put_multi,
99+
put_multi_async,
100+
)
93101
from google.cloud.ndb.polymodel import PolyModel
94-
from google.cloud.ndb.query import ConjunctionNode
95-
from google.cloud.ndb.query import AND
96-
from google.cloud.ndb.query import DisjunctionNode
97-
from google.cloud.ndb.query import OR
98-
from google.cloud.ndb.query import FalseNode
99-
from google.cloud.ndb.query import FilterNode
100-
from google.cloud.ndb.query import gql
101-
from google.cloud.ndb.query import Node
102-
from google.cloud.ndb.query import Parameter
103-
from google.cloud.ndb.query import ParameterizedFunction
104-
from google.cloud.ndb.query import ParameterizedThing
105-
from google.cloud.ndb.query import ParameterNode
106-
from google.cloud.ndb.query import PostFilterNode
107-
from google.cloud.ndb.query import Query
108-
from google.cloud.ndb.query import QueryOptions
109-
from google.cloud.ndb.query import RepeatedStructuredPropertyPredicate
110-
from google.cloud.ndb.tasklets import add_flow_exception
111-
from google.cloud.ndb.tasklets import Future
112-
from google.cloud.ndb.tasklets import make_context
113-
from google.cloud.ndb.tasklets import make_default_context
114-
from google.cloud.ndb.tasklets import QueueFuture
115-
from google.cloud.ndb.tasklets import ReducingFuture
116-
from google.cloud.ndb.tasklets import Return
117-
from google.cloud.ndb.tasklets import SerialQueueFuture
118-
from google.cloud.ndb.tasklets import set_context
119-
from google.cloud.ndb.tasklets import sleep
120-
from google.cloud.ndb.tasklets import synctasklet
121-
from google.cloud.ndb.tasklets import tasklet
122-
from google.cloud.ndb.tasklets import toplevel
123-
from google.cloud.ndb.tasklets import wait_all
124-
from google.cloud.ndb.tasklets import wait_any
125-
from google.cloud.ndb._transaction import in_transaction
126-
from google.cloud.ndb._transaction import transaction
127-
from google.cloud.ndb._transaction import transaction_async
128-
from google.cloud.ndb._transaction import transactional
129-
from google.cloud.ndb._transaction import transactional_async
130-
from google.cloud.ndb._transaction import transactional_tasklet
131-
from google.cloud.ndb._transaction import non_transactional
102+
from google.cloud.ndb.query import (
103+
AND,
104+
OR,
105+
ConjunctionNode,
106+
DisjunctionNode,
107+
FalseNode,
108+
FilterNode,
109+
Node,
110+
Parameter,
111+
ParameterizedFunction,
112+
ParameterizedThing,
113+
ParameterNode,
114+
PostFilterNode,
115+
Query,
116+
QueryOptions,
117+
RepeatedStructuredPropertyPredicate,
118+
gql,
119+
)
120+
from google.cloud.ndb.tasklets import (
121+
Future,
122+
QueueFuture,
123+
ReducingFuture,
124+
Return,
125+
SerialQueueFuture,
126+
add_flow_exception,
127+
make_context,
128+
make_default_context,
129+
set_context,
130+
sleep,
131+
synctasklet,
132+
tasklet,
133+
toplevel,
134+
wait_all,
135+
wait_any,
136+
)
132137

133138
__all__ = [
134139
"__version__",

packages/google-cloud-ndb/google/cloud/ndb/_cache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
from google.api_core import retry as core_retry
2222

23-
from google.cloud.ndb import _batch
23+
from google.cloud.ndb import _batch, tasklets, utils
2424
from google.cloud.ndb import context as context_module
25-
from google.cloud.ndb import tasklets
26-
from google.cloud.ndb import utils
2725

2826
_LOCKED_FOR_READ = b"0-"
2927
_LOCKED_FOR_WRITE = b"00"

packages/google-cloud-ndb/google/cloud/ndb/_datastore_api.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@
1414

1515
"""Functions that interact with Datastore backend."""
1616

17-
import grpc
1817
import itertools
1918
import logging
2019

20+
import grpc
2121
from google.api_core import exceptions as core_exceptions
2222
from google.api_core import gapic_v1
2323
from google.cloud.datastore import helpers
2424
from google.cloud.datastore_v1.types import datastore as datastore_pb2
2525
from google.cloud.datastore_v1.types import entity as entity_pb2
2626

27+
from google.cloud.ndb import (
28+
_batch,
29+
_cache,
30+
_eventloop,
31+
_options,
32+
_remote,
33+
_retry,
34+
tasklets,
35+
utils,
36+
)
2737
from google.cloud.ndb import context as context_module
28-
from google.cloud.ndb import _batch
29-
from google.cloud.ndb import _cache
30-
from google.cloud.ndb import _eventloop
31-
from google.cloud.ndb import _options
32-
from google.cloud.ndb import _remote
33-
from google.cloud.ndb import _retry
34-
from google.cloud.ndb import tasklets
35-
from google.cloud.ndb import utils
3638

3739
EVENTUAL = datastore_pb2.ReadOptions.ReadConsistency.EVENTUAL
3840
EVENTUAL_CONSISTENCY = EVENTUAL # Legacy NDB

packages/google-cloud-ndb/google/cloud/ndb/_datastore_query.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,15 @@
2020
import logging
2121
import os
2222

23-
from google.cloud import environment_vars
24-
23+
from google.cloud.datastore import Key, helpers
2524
from google.cloud.datastore_v1.types import datastore as datastore_pb2
2625
from google.cloud.datastore_v1.types import entity as entity_pb2
2726
from google.cloud.datastore_v1.types import query as query_pb2
28-
from google.cloud.datastore import helpers, Key
2927

28+
from google.cloud import environment_vars
29+
from google.cloud.ndb import _datastore_api, exceptions, model, tasklets, utils
3030
from google.cloud.ndb import context as context_module
31-
from google.cloud.ndb import _datastore_api
32-
from google.cloud.ndb import exceptions
3331
from google.cloud.ndb import key as key_module
34-
from google.cloud.ndb import model
35-
from google.cloud.ndb import tasklets
36-
from google.cloud.ndb import utils
3732

3833
log = logging.getLogger(__name__)
3934

packages/google-cloud-ndb/google/cloud/ndb/_datastore_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from google.cloud.ndb import exceptions
2626

27-
2827
_MAX_STRING_LENGTH = 1500
2928

3029

@@ -55,12 +54,13 @@ def __init__(self, blob_key):
5554
if isinstance(blob_key, bytes):
5655
if len(blob_key) > _MAX_STRING_LENGTH:
5756
raise exceptions.BadValueError(
58-
"blob key must be under {:d} " "bytes.".format(_MAX_STRING_LENGTH)
57+
"blob key must be under {:d} bytes.".format(_MAX_STRING_LENGTH)
5958
)
6059
elif blob_key is not None:
6160
raise exceptions.BadValueError(
62-
"blob key should be bytes; received "
63-
"{} (a {})".format(blob_key, type(blob_key).__name__)
61+
"blob key should be bytes; received {} (a {})".format(
62+
blob_key, type(blob_key).__name__
63+
)
6464
)
6565

6666
self._blob_key = blob_key

packages/google-cloud-ndb/google/cloud/ndb/_eventloop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
1717
This should handle both asynchronous ``ndb`` objects and arbitrary callbacks.
1818
"""
19+
1920
import collections
2021
import logging
21-
import uuid
22-
import time
23-
2422
import queue
23+
import time
24+
import uuid
2525

2626
from google.cloud.ndb import utils
2727

packages/google-cloud-ndb/google/cloud/ndb/_gql.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import time
44
from typing import Any
55

6+
from google.cloud.ndb import _datastore_query, exceptions, key, model
67
from google.cloud.ndb import context as context_module
7-
from google.cloud.ndb import exceptions
88
from google.cloud.ndb import query as query_module
9-
from google.cloud.ndb import key
10-
from google.cloud.ndb import model
11-
from google.cloud.ndb import _datastore_query
129

1310

1411
class GQL(object):

packages/google-cloud-ndb/google/cloud/ndb/_legacy_protocol_buffer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import array
1717
import struct
1818

19-
2019
# Python 3 doesn't have "long" anymore
2120
long = int
2221

packages/google-cloud-ndb/google/cloud/ndb/_options.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import functools
1818
import itertools
1919
import logging
20+
from typing import Any
2021

2122
from google.cloud.ndb import exceptions
22-
from typing import Any
2323

2424
log = logging.getLogger(__name__)
2525

@@ -135,8 +135,7 @@ def __init__(self, config=None, **kwargs):
135135
global_cache_timeout = kwargs.get("global_cache_timeout")
136136
if global_cache_timeout is not None:
137137
raise TypeError(
138-
"Can't specify both 'memcache_timeout' and "
139-
"'global_cache_timeout'"
138+
"Can't specify both 'memcache_timeout' and 'global_cache_timeout'"
140139
)
141140
kwargs["global_cache_timeout"] = memcache_timeout
142141

@@ -223,7 +222,7 @@ def __init__(self, config=None, **kwargs):
223222
)
224223
if kwargs.get("read_consistency"):
225224
raise TypeError(
226-
"Cannot use both 'read_policy' and 'read_consistency' " "options."
225+
"Cannot use both 'read_policy' and 'read_consistency' options."
227226
)
228227
kwargs["read_consistency"] = read_policy
229228

packages/google-cloud-ndb/google/cloud/ndb/_remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
# In its own module to avoid circular import between _datastore_api and
1818
# tasklets modules.
19-
import grpc
2019
import time
2120

21+
import grpc
22+
2223
from google.cloud.ndb import exceptions
2324

2425

0 commit comments

Comments
 (0)