Skip to content
35 changes: 27 additions & 8 deletions sdk/tables/azure-data-tables/azure/data/tables/_table_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# --------------------------------------------------------------------------

import functools
from typing import Optional, Any, Union, List, Tuple, Dict, Mapping, Iterable
from typing import Optional, Any, Union, List, Tuple, Dict, Mapping, Iterable, overload
try:
from urllib.parse import urlparse, unquote
except ImportError:
Expand Down Expand Up @@ -273,14 +273,19 @@ def delete_table(
except HttpResponseError as error:
_process_table_error(error)

@overload
def delete_entity(self, partition_key, row_key, **kwargs):
# type: (str, str, Any) -> None
pass
Comment thread
annatisch marked this conversation as resolved.

@overload
def delete_entity(self, entity, **kwargs):
# type: (Union[TableEntity, Mapping[str, Any]], Any) -> None
pass

@distributed_trace
def delete_entity(
self,
partition_key, # type: str
row_key, # type: str
**kwargs # type: Any
):
# type: (...) -> None
def delete_entity(self, *args, **kwargs):
# type: (Union[TableEntity, str], Any) -> None
"""Deletes the specified entity in a table.

:param partition_key: The partition key of the entity.
Expand All @@ -303,6 +308,20 @@ def delete_entity(
:dedent: 8
:caption: Deleting an entity to a Table
"""
try:
entity = kwargs.pop('entity', None)
if not entity:
entity = args[0]
partition_key = entity['PartitionKey']
row_key = entity['RowKey']
except (TypeError, IndexError):
Comment thread
seankane-msft marked this conversation as resolved.
partition_key = kwargs.pop('partition_key', None)
if not partition_key:
partition_key = args[0]
row_key = kwargs.pop("row_key", None)
if not row_key:
Comment thread
annatisch marked this conversation as resolved.
row_key = args[1]


if_match, _ = _get_match_headers(
kwargs=dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# --------------------------------------------------------------------------
import functools
from typing import List, Union, Any, Optional, Mapping, Iterable
from typing import List, Union, Any, Optional, Mapping, Iterable, Dict, overload
try:
from urllib.parse import urlparse, unquote
except ImportError:
Expand Down Expand Up @@ -264,13 +264,16 @@ async def delete_table(self, **kwargs) -> None:
except HttpResponseError as error:
_process_table_error(error)

@overload
async def delete_entity(self, partition_key: str, row_key: str, **kwargs: Any) -> None:
...

@overload
async def delete_entity(self, entity: Union[TableEntity, Mapping[str, Any]], **kwargs: Any) -> None:
...

@distributed_trace_async
async def delete_entity(
self,
partition_key: str,
row_key: str,
**kwargs
) -> None:
async def delete_entity(self, *args: Union[TableEntity, str], **kwargs: Any) -> None:
"""Deletes the specified entity in a table.

:param partition_key: The partition key of the entity.
Expand All @@ -293,6 +296,20 @@ async def delete_entity(
:dedent: 8
:caption: Adding an entity to a Table
"""
try:
entity = kwargs.pop('entity', None)
if not entity:
entity = args[0]
partition_key = entity['PartitionKey']
row_key = entity['RowKey']
except (TypeError, IndexError):
partition_key = kwargs.pop('partition_key', None)
if not partition_key:
partition_key = args[0]
row_key = kwargs.pop("row_key", None)
if not row_key:
row_key = args[1]

if_match, _ = _get_match_headers(
kwargs=dict(
kwargs,
Expand Down
Loading