Skip to content

Commit ec2312c

Browse files
committed
fix(ndb): fix mypy errors and undefined Any name
1 parent 9934515 commit ec2312c

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def _entity_to_ds_entity(entity, set_key=True):
761761
Raises:
762762
ndb.exceptions.BadValueError: If entity has uninitialized properties.
763763
"""
764-
data: dict[str, Any] = {"_exclude_from_indexes": []}
764+
data: dict[str, typing.Any] = {"_exclude_from_indexes": []}
765765
uninitialized = []
766766

767767
for prop in _properties_of(entity):
@@ -3577,6 +3577,31 @@ def _to_datastore(self, entity, data, prefix="", repeated=False):
35773577
)
35783578

35793579

3580+
def _handle_key_property_positional(wrapped):
3581+
@functools.wraps(wrapped)
3582+
def wrapper(self, *args, **kwargs):
3583+
for arg in args:
3584+
if isinstance(arg, str):
3585+
if "name" in kwargs:
3586+
raise TypeError("You can only specify name once")
3587+
3588+
kwargs["name"] = arg
3589+
3590+
elif isinstance(arg, type):
3591+
if "kind" in kwargs:
3592+
raise TypeError("You can only specify kind once")
3593+
3594+
kwargs["kind"] = arg
3595+
3596+
elif arg is not None:
3597+
raise TypeError("Unexpected positional argument: {!r}".format(arg))
3598+
3599+
return wrapped(self, **kwargs)
3600+
3601+
wrapper._wrapped = wrapped # type: ignore[attr-defined]
3602+
return wrapper
3603+
3604+
35803605
class KeyProperty(Property):
35813606
"""A property that contains :class:`~google.cloud.ndb.key.Key` values.
35823607
@@ -3633,32 +3658,8 @@ class SimpleModel(ndb.Model):
36333658

36343659
_kind = None
36353660

3636-
def _handle_positional(wrapped):
3637-
@functools.wraps(wrapped)
3638-
def wrapper(self, *args, **kwargs):
3639-
for arg in args:
3640-
if isinstance(arg, str):
3641-
if "name" in kwargs:
3642-
raise TypeError("You can only specify name once")
3643-
3644-
kwargs["name"] = arg
3645-
3646-
elif isinstance(arg, type):
3647-
if "kind" in kwargs:
3648-
raise TypeError("You can only specify kind once")
3649-
3650-
kwargs["kind"] = arg
3651-
3652-
elif arg is not None:
3653-
raise TypeError("Unexpected positional argument: {!r}".format(arg))
3654-
3655-
return wrapped(self, **kwargs)
3656-
3657-
wrapper._wrapped = wrapped # type: ignore[attr-defined]
3658-
return wrapper
3659-
36603661
@utils.positional(3)
3661-
@_handle_positional
3662+
@_handle_key_property_positional
36623663
def __init__(
36633664
self,
36643665
name=None,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ def __contains__(self, key):
16201620
return True
16211621

16221622
bindings = MockBindings()
1623-
used: dict[Any, Any] = {}
1623+
used: dict[typing.Any, typing.Any] = {}
16241624
ancestor = self.ancestor
16251625
if isinstance(ancestor, ParameterizedThing):
16261626
ancestor = ancestor.resolve(bindings, used)
@@ -1650,10 +1650,10 @@ def bind(self, *positional, **keyword):
16501650
google.cloud.ndb.exceptions.BadArgumentError: If one of
16511651
the positional parameters is not used in the query.
16521652
"""
1653-
bindings: dict[Any, Any] = dict(keyword)
1653+
bindings: dict[typing.Any, typing.Any] = dict(keyword)
16541654
for i, arg in enumerate(positional):
16551655
bindings[i + 1] = arg
1656-
used: dict[Any, Any] = {}
1656+
used: dict[typing.Any, typing.Any] = {}
16571657
ancestor = self.ancestor
16581658
if isinstance(ancestor, ParameterizedThing):
16591659
ancestor = ancestor.resolve(bindings, used)

0 commit comments

Comments
 (0)