Skip to content

Commit 1c7fc6c

Browse files
gavin-aguiarGavin Aguiar
and
Gavin Aguiar
authored
Moved SqlRow from _abc (#150)
* Moved SqlRow from _abc * Fixing mypy errors * Removing py36 * Resolving conflicts * Updated abstract class Co-authored-by: Gavin Aguiar <gavin@GavinPC>
1 parent 0f155a9 commit 1c7fc6c

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

azure/functions/_abc.py

-29
Original file line numberDiff line numberDiff line change
@@ -422,32 +422,3 @@ class OrchestrationContext(abc.ABC):
422422
@abc.abstractmethod
423423
def body(self) -> str:
424424
pass
425-
426-
427-
class SqlRow(abc.ABC):
428-
429-
@classmethod
430-
@abc.abstractmethod
431-
def from_json(cls, json_data: str) -> 'SqlRow':
432-
pass
433-
434-
@classmethod
435-
@abc.abstractmethod
436-
def from_dict(cls, dct: dict) -> 'SqlRow':
437-
pass
438-
439-
@abc.abstractmethod
440-
def __getitem__(self, key):
441-
pass
442-
443-
@abc.abstractmethod
444-
def __setitem__(self, key, value):
445-
pass
446-
447-
@abc.abstractmethod
448-
def to_json(self) -> str:
449-
pass
450-
451-
452-
class SqlRowList(abc.ABC):
453-
pass

azure/functions/_sql.py

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
3+
import abc
44
import collections
55
import json
66

7-
from . import _abc
7+
8+
class BaseSqlRow(abc.ABC):
9+
10+
@classmethod
11+
@abc.abstractmethod
12+
def from_json(cls, json_data: str) -> 'BaseSqlRow':
13+
raise NotImplementedError
14+
15+
@classmethod
16+
@abc.abstractmethod
17+
def from_dict(cls, dct: dict) -> 'BaseSqlRow':
18+
raise NotImplementedError
19+
20+
@abc.abstractmethod
21+
def __getitem__(self, key):
22+
raise NotImplementedError
23+
24+
@abc.abstractmethod
25+
def __setitem__(self, key, value):
26+
raise NotImplementedError
27+
28+
@abc.abstractmethod
29+
def to_json(self) -> str:
30+
raise NotImplementedError
31+
32+
33+
class BaseSqlRowList(abc.ABC):
34+
pass
835

936

10-
class SqlRow(_abc.SqlRow, collections.UserDict):
37+
class SqlRow(BaseSqlRow, collections.UserDict):
1138
"""A SQL Row.
1239
1340
SqlRow objects are ''UserDict'' subclasses and behave like dicts.
1441
"""
1542

1643
@classmethod
17-
def from_json(cls, json_data: str) -> 'SqlRow':
44+
def from_json(cls, json_data: str) -> 'BaseSqlRow':
1845
"""Create a SqlRow from a JSON string."""
1946
return cls.from_dict(json.loads(json_data))
2047

2148
@classmethod
22-
def from_dict(cls, dct: dict) -> 'SqlRow':
49+
def from_dict(cls, dct: dict) -> 'BaseSqlRow':
2350
"""Create a SqlRow from a dict object"""
2451
return cls({k: v for k, v in dct.items()})
2552

@@ -39,6 +66,6 @@ def __repr__(self) -> str:
3966
)
4067

4168

42-
class SqlRowList(_abc.SqlRowList, collections.UserList):
69+
class SqlRowList(BaseSqlRowList, collections.UserList):
4370
"A ''UserList'' subclass containing a list of :class:'~SqlRow' objects"
4471
pass

azure/functions/sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class SqlConverter(meta.InConverter, meta.OutConverter,
1515

1616
@classmethod
1717
def check_input_type_annotation(cls, pytype: type) -> bool:
18-
return issubclass(pytype, sql.SqlRowList)
18+
return issubclass(pytype, sql.BaseSqlRowList)
1919

2020
@classmethod
2121
def check_output_type_annotation(cls, pytype: type) -> bool:
22-
return issubclass(pytype, (sql.SqlRowList, sql.SqlRow))
22+
return issubclass(pytype, (sql.BaseSqlRowList, sql.BaseSqlRow))
2323

2424
@classmethod
2525
def decode(cls,

tests/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
import json
45
import unittest
56

67
import azure.functions as func
78
import azure.functions.sql as sql
89
from azure.functions.meta import Datum
9-
import json
1010

1111

1212
class TestSql(unittest.TestCase):

0 commit comments

Comments
 (0)