Skip to content

Moved SqlRow from _abc #150

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 9 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/gh-tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: [3.6, 3.7, 3.8, 3.9, "3.10"]
python_version: [3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python_version }}
Expand Down
29 changes: 0 additions & 29 deletions azure/functions/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,32 +433,3 @@ class OrchestrationContext(abc.ABC):
@abc.abstractmethod
def body(self) -> str:
pass


class SqlRow(abc.ABC):

@classmethod
@abc.abstractmethod
def from_json(cls, json_data: str) -> 'SqlRow':
pass

@classmethod
@abc.abstractmethod
def from_dict(cls, dct: dict) -> 'SqlRow':
pass

@abc.abstractmethod
def __getitem__(self, key):
pass

@abc.abstractmethod
def __setitem__(self, key, value):
pass

@abc.abstractmethod
def to_json(self) -> str:
pass


class SqlRowList(abc.ABC):
pass
39 changes: 33 additions & 6 deletions azure/functions/_sql.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import abc
import collections
import json

from . import _abc

class BaseSqlRow(abc.ABC):

@classmethod
@abc.abstractmethod
def from_json(cls, json_data: str) -> 'BaseSqlRow':
pass

@classmethod
@abc.abstractmethod
def from_dict(cls, dct: dict) -> 'BaseSqlRow':
pass

@abc.abstractmethod
def __getitem__(self, key):
pass

@abc.abstractmethod
def __setitem__(self, key, value):
pass

@abc.abstractmethod
def to_json(self) -> str:
pass


class BaseSqlRowList(abc.ABC):
pass


class SqlRow(_abc.SqlRow, collections.UserDict):
class SqlRow(BaseSqlRow, collections.UserDict):
"""A SQL Row.

SqlRow objects are ''UserDict'' subclasses and behave like dicts.
"""

@classmethod
def from_json(cls, json_data: str) -> 'SqlRow':
def from_json(cls, json_data: str) -> 'BaseSqlRow':
"""Create a SqlRow from a JSON string."""
return cls.from_dict(json.loads(json_data))

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

Expand All @@ -39,6 +66,6 @@ def __repr__(self) -> str:
)


class SqlRowList(_abc.SqlRowList, collections.UserList):
class SqlRowList(BaseSqlRowList, collections.UserList):
"A ''UserList'' subclass containing a list of :class:'~SqlRow' objects"
pass
4 changes: 2 additions & 2 deletions azure/functions/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class SqlConverter(meta.InConverter, meta.OutConverter,

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

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

@classmethod
def decode(cls,
Expand Down