Skip to content

Stubs for google.cloud.ndb the Google Cloud Datastore ndb client library #5821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3691112
Stubs for google.cloud.ndb
romanofski Jul 30, 2021
837aafe
Remove private imports and functions
romanofski Jul 30, 2021
f4a037c
This is not needed
romanofski Jul 30, 2021
2cb9471
Address metadata problems
romanofski Jul 31, 2021
68b2a83
(partial) type annotations for ndb.model
romanofski Jul 31, 2021
351886c
Rename to fit with PyPi package
romanofski Aug 1, 2021
1718936
Needed dependencies for stubtest
romanofski Aug 1, 2021
7dca4d2
More typing annotations
romanofski Aug 3, 2021
d2789ce
New stubgen run to avoid Any typings
romanofski Aug 3, 2021
94ff108
Fix mypy errors
romanofski Aug 5, 2021
a5d688a
Add types to the __get__/__set__ protocols
romanofski Aug 6, 2021
29a657c
Overwrite more descriptors
romanofski Aug 10, 2021
10c2cb8
Add google-cloud-ndb to stricter pyright conf
romanofski Aug 11, 2021
1b3a7cc
Eliminate the use of Any
romanofski Aug 11, 2021
c338770
type enums as literals
romanofski Aug 17, 2021
4ad78ae
Address more pyright errors
romanofski Aug 17, 2021
9274320
Redefine protobuf enum for proper typing
romanofski Aug 17, 2021
13bfa37
Go back to use the Literal as it comes closer to the actual enum
romanofski Aug 18, 2021
c068080
"Improved" type, albeit still a union type :/
romanofski Aug 18, 2021
dcf5c2a
Address stubtest
romanofski Aug 18, 2021
1142f0d
NoReturn for __new__ is invalid here, don't type annotate it
romanofski Aug 18, 2021
9949f0a
Generated allowlist
romanofski Aug 18, 2021
7c132e6
Remove unused import
romanofski Aug 18, 2021
c07cb3b
Remove methods not present at runtime
romanofski Aug 18, 2021
a79eeff
Address stubtest
romanofski Sep 6, 2021
5e98b3e
Remove dict to avoid to confuse the types
romanofski Sep 6, 2021
906226f
Comply with PEP 604
romanofski Sep 7, 2021
f4493ac
Comply with PEP 604 - part II
romanofski Sep 8, 2021
a58700d
Remove unused import
romanofski Sep 8, 2021
bcbdece
Address stubtest failures due to refactoring
romanofski Sep 8, 2021
ead09e9
Address error in typing for datastore api
romanofski Sep 26, 2021
0c6e8ed
Address version syntax change to include patch
romanofski Oct 21, 2021
ee398de
Merge remote-tracking branch 'python/master' into feat/google-cloud-ndb
romanofski Oct 21, 2021
d38ddd7
Use built-in generics
romanofski Oct 21, 2021
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
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"stubs/paramiko",
"stubs/prettytable",
"stubs/protobuf",
"stubs/google-cloud-ndb",
"stubs/psutil",
"stubs/psycopg2",
"stubs/Pygments",
Expand Down
4 changes: 4 additions & 0 deletions stubs/google-cloud-ndb/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# inconsistency of signatures between stub and implementation (cls vs self)
google.cloud.ndb.ModelAdapter.__new__
google.cloud.ndb.metadata.EntityGroup.__new__
google.cloud.ndb.model.ModelAdapter.__new__
2 changes: 2 additions & 0 deletions stubs/google-cloud-ndb/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "1.9"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax has changed:

Suggested change
version = "1.9"
version = "1.9.*"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Thanks for pointing it out.

requires = ["types-six"]
Empty file.
Empty file.
109 changes: 109 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from google.cloud.ndb._datastore_api import EVENTUAL as EVENTUAL, EVENTUAL_CONSISTENCY as EVENTUAL_CONSISTENCY, STRONG as STRONG
from google.cloud.ndb._datastore_query import Cursor as Cursor, QueryIterator as QueryIterator
from google.cloud.ndb._transaction import (
in_transaction as in_transaction,
non_transactional as non_transactional,
transaction as transaction,
transaction_async as transaction_async,
transactional as transactional,
transactional_async as transactional_async,
transactional_tasklet as transactional_tasklet,
)
from google.cloud.ndb.client import Client as Client
from google.cloud.ndb.context import (
AutoBatcher as AutoBatcher,
Context as Context,
ContextOptions as ContextOptions,
TransactionOptions as TransactionOptions,
get_context as get_context,
get_toplevel_context as get_toplevel_context,
)
from google.cloud.ndb.global_cache import GlobalCache as GlobalCache, MemcacheCache as MemcacheCache, RedisCache as RedisCache
from google.cloud.ndb.key import Key as Key
from google.cloud.ndb.model import (
BadProjectionError as BadProjectionError,
BlobKey as BlobKey,
BlobKeyProperty as BlobKeyProperty,
BlobProperty as BlobProperty,
BooleanProperty as BooleanProperty,
ComputedProperty as ComputedProperty,
ComputedPropertyError as ComputedPropertyError,
DateProperty as DateProperty,
DateTimeProperty as DateTimeProperty,
Expando as Expando,
FloatProperty as FloatProperty,
GenericProperty as GenericProperty,
GeoPt as GeoPt,
GeoPtProperty as GeoPtProperty,
Index as Index,
IndexProperty as IndexProperty,
IndexState as IndexState,
IntegerProperty as IntegerProperty,
InvalidPropertyError as InvalidPropertyError,
JsonProperty as JsonProperty,
KeyProperty as KeyProperty,
KindError as KindError,
LocalStructuredProperty as LocalStructuredProperty,
MetaModel as MetaModel,
Model as Model,
ModelAdapter as ModelAdapter,
ModelAttribute as ModelAttribute,
ModelKey as ModelKey,
PickleProperty as PickleProperty,
Property as Property,
ReadonlyPropertyError as ReadonlyPropertyError,
Rollback as Rollback,
StringProperty as StringProperty,
StructuredProperty as StructuredProperty,
TextProperty as TextProperty,
TimeProperty as TimeProperty,
UnprojectedPropertyError as UnprojectedPropertyError,
User as User,
UserNotFoundError as UserNotFoundError,
UserProperty as UserProperty,
delete_multi as delete_multi,
delete_multi_async as delete_multi_async,
get_indexes as get_indexes,
get_indexes_async as get_indexes_async,
get_multi as get_multi,
get_multi_async as get_multi_async,
make_connection as make_connection,
put_multi as put_multi,
put_multi_async as put_multi_async,
)
from google.cloud.ndb.polymodel import PolyModel as PolyModel
from google.cloud.ndb.query import (
AND as AND,
OR as OR,
ConjunctionNode as ConjunctionNode,
DisjunctionNode as DisjunctionNode,
FalseNode as FalseNode,
FilterNode as FilterNode,
Node as Node,
Parameter as Parameter,
ParameterizedFunction as ParameterizedFunction,
ParameterizedThing as ParameterizedThing,
ParameterNode as ParameterNode,
PostFilterNode as PostFilterNode,
Query as Query,
QueryOptions as QueryOptions,
RepeatedStructuredPropertyPredicate as RepeatedStructuredPropertyPredicate,
gql as gql,
)
from google.cloud.ndb.tasklets import (
Future as Future,
QueueFuture as QueueFuture,
ReducingFuture as ReducingFuture,
Return as Return,
SerialQueueFuture as SerialQueueFuture,
add_flow_exception as add_flow_exception,
make_context as make_context,
make_default_context as make_default_context,
set_context as set_context,
sleep as sleep,
synctasklet as synctasklet,
tasklet as tasklet,
toplevel as toplevel,
wait_all as wait_all,
wait_any as wait_any,
)
3 changes: 3 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_batch.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def get_batch(batch_cls, options: Any | None = ...): ...
72 changes: 72 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_cache.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from typing import Any

from google.cloud.ndb import tasklets as tasklets

class ContextCache:
def get_and_validate(self, key): ...

class _GlobalCacheBatch:
def full(self): ...
def idle_callback(self) -> None: ...
def done_callback(self, cache_call) -> None: ...
def make_call(self) -> None: ...
def future_info(self, key) -> None: ...

global_get: Any

class _GlobalCacheGetBatch(_GlobalCacheBatch):
todo: Any
keys: Any
def __init__(self, ignore_options) -> None: ...
def add(self, key): ...
def done_callback(self, cache_call) -> None: ...
def make_call(self): ...
def future_info(self, key): ...

def global_set(key, value, expires: Any | None = ..., read: bool = ...): ...

class _GlobalCacheSetBatch(_GlobalCacheBatch):
expires: Any
todo: object
futures: object
def __init__(self, options) -> None: ...
def done_callback(self, cache_call) -> None: ...
def add(self, key, value): ...
def make_call(self): ...
def future_info(self, key, value): ...

class _GlobalCacheSetIfNotExistsBatch(_GlobalCacheSetBatch):
def add(self, key, value): ...
def make_call(self): ...
def future_info(self, key, value): ...

global_delete: Any

class _GlobalCacheDeleteBatch(_GlobalCacheBatch):
keys: Any
futures: Any
def __init__(self, ignore_options) -> None: ...
def add(self, key): ...
def make_call(self): ...
def future_info(self, key): ...

global_watch: Any

class _GlobalCacheWatchBatch(_GlobalCacheDeleteBatch):
def make_call(self): ...
def future_info(self, key): ...

def global_unwatch(key): ...

class _GlobalCacheUnwatchBatch(_GlobalCacheDeleteBatch):
def make_call(self): ...
def future_info(self, key): ...

global_compare_and_swap: Any

class _GlobalCacheCompareAndSwapBatch(_GlobalCacheSetBatch):
def make_call(self): ...
def future_info(self, key, value): ...

def is_locked_value(value): ...
def global_cache_key(key): ...
5 changes: 5 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_datastore_api.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing_extensions import Literal

EVENTUAL: Literal[2]
EVENTUAL_CONSISTENCY: Literal[2]
STRONG: Literal[1]
22 changes: 22 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_datastore_query.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Any

class QueryIterator:
def __iter__(self): ...
def has_next(self) -> None: ...
def has_next_async(self) -> None: ...
def probably_has_next(self) -> None: ...
def next(self) -> None: ...
def cursor_before(self) -> None: ...
def cursor_after(self) -> None: ...
def index_list(self) -> None: ...

class Cursor:
@classmethod
def from_websafe_string(cls, urlsafe): ...
cursor: Any
def __init__(self, cursor: Any | None = ..., urlsafe: Any | None = ...) -> None: ...
def to_websafe_string(self): ...
def urlsafe(self): ...
def __eq__(self, other): ...
def __ne__(self, other): ...
def __hash__(self): ...
26 changes: 26 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_eventloop.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Any, NamedTuple

class _Event(NamedTuple):
when: Any
callback: Any
args: Any
kwargs: Any

class EventLoop:
current: Any
idlers: Any
inactive: int
queue: Any
rpcs: Any
rpc_results: Any
def __init__(self) -> None: ...
def clear(self) -> None: ...
def insort_event_right(self, event) -> None: ...
def call_soon(self, callback, *args, **kwargs) -> None: ...
def queue_call(self, delay, callback, *args, **kwargs) -> None: ...
def queue_rpc(self, rpc, callback) -> None: ...
def add_idle(self, callback, *args, **kwargs) -> None: ...
def run_idle(self): ...
def run0(self): ...
def run1(self): ...
def run(self) -> None: ...
15 changes: 15 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_options.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any

class Options:
@classmethod
def options(cls, wrapped): ...
@classmethod
def slots(cls): ...
def __init__(self, config: Any | None = ..., **kwargs) -> None: ...
def __eq__(self, other): ...
def __ne__(self, other): ...
def copy(self, **kwargs): ...
def items(self) -> None: ...

class ReadOptions(Options):
def __init__(self, config: Any | None = ..., **kwargs) -> None: ...
18 changes: 18 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/_transaction.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any

def in_transaction(): ...
def transaction(
callback, retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...
): ...
def transaction_async(
callback, retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...
): ...
def transaction_async_(
callback, retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...
): ...
def transactional(retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...): ...
def transactional_async(retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...): ...
def transactional_tasklet(
retries=..., read_only: bool = ..., join: bool = ..., xg: bool = ..., propagation: Any | None = ...
): ...
def non_transactional(allow_existing: bool = ...): ...
65 changes: 65 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/blobstore.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import Any

from google.cloud.ndb import model

BlobKey: Any
BLOB_INFO_KIND: str
BLOB_MIGRATION_KIND: str
BLOB_KEY_HEADER: str
BLOB_RANGE_HEADER: str
MAX_BLOB_FETCH_SIZE: int
UPLOAD_INFO_CREATION_HEADER: str
BlobKeyProperty = model.BlobKeyProperty

class BlobFetchSizeTooLargeError:
def __init__(self, *args, **kwargs) -> None: ...

class BlobInfo:
def __init__(self, *args, **kwargs) -> None: ...
@classmethod
def get(cls, *args, **kwargs) -> None: ...
@classmethod
def get_async(cls, *args, **kwargs) -> None: ...
@classmethod
def get_multi(cls, *args, **kwargs) -> None: ...
@classmethod
def get_multi_async(cls, *args, **kwargs) -> None: ...

class BlobInfoParseError:
def __init__(self, *args, **kwargs) -> None: ...

class BlobNotFoundError:
def __init__(self, *args, **kwargs) -> None: ...

class BlobReader:
def __init__(self, *args, **kwargs) -> None: ...

def create_upload_url(*args, **kwargs) -> None: ...
def create_upload_url_async(*args, **kwargs) -> None: ...

class DataIndexOutOfRangeError:
def __init__(self, *args, **kwargs) -> None: ...

def delete(*args, **kwargs) -> None: ...
def delete_async(*args, **kwargs) -> None: ...
def delete_multi(*args, **kwargs) -> None: ...
def delete_multi_async(*args, **kwargs) -> None: ...

class Error:
def __init__(self, *args, **kwargs) -> None: ...

def fetch_data(*args, **kwargs) -> None: ...
def fetch_data_async(*args, **kwargs) -> None: ...

get: Any
get_async: Any
get_multi: Any
get_multi_async: Any

class InternalError:
def __init__(self, *args, **kwargs) -> None: ...

def parse_blob_info(*args, **kwargs) -> None: ...

class PermissionDeniedError:
def __init__(self, *args, **kwargs) -> None: ...
21 changes: 21 additions & 0 deletions stubs/google-cloud-ndb/google/cloud/ndb/client.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Any

DATASTORE_API_HOST: Any

class Client:
SCOPE: Any
namespace: Any
host: Any
client_info: Any
secure: Any
stub: Any
def __init__(self, project: Any | None = ..., namespace: Any | None = ..., credentials: Any | None = ...) -> None: ...
def context(
self,
namespace=...,
cache_policy: Any | None = ...,
global_cache: Any | None = ...,
global_cache_policy: Any | None = ...,
global_cache_timeout_policy: Any | None = ...,
legacy_data: bool = ...,
) -> None: ...
Loading