From 5a9e7711b7db53fef095539b135f5ac3b1655047 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Fri, 11 Nov 2022 23:51:19 -0600 Subject: [PATCH 1/5] Moved SqlRow from _abc --- azure/functions/_abc.py | 29 ----------------------------- azure/functions/_sql.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/azure/functions/_abc.py b/azure/functions/_abc.py index 2470fe92..ea928a09 100644 --- a/azure/functions/_abc.py +++ b/azure/functions/_abc.py @@ -422,32 +422,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 diff --git a/azure/functions/_sql.py b/azure/functions/_sql.py index a673c320..3bedfb48 100644 --- a/azure/functions/_sql.py +++ b/azure/functions/_sql.py @@ -1,13 +1,40 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. - +import abc import collections import json -from . import _abc + +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 -class SqlRow(_abc.SqlRow, collections.UserDict): +class SqlRow(SqlRow, collections.UserDict): """A SQL Row. SqlRow objects are ''UserDict'' subclasses and behave like dicts. @@ -39,6 +66,6 @@ def __repr__(self) -> str: ) -class SqlRowList(_abc.SqlRowList, collections.UserList): +class SqlRowList(SqlRowList, collections.UserList): "A ''UserList'' subclass containing a list of :class:'~SqlRow' objects" pass From 784cb850783eedb4332d1833a7e7a54ba19391b9 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Thu, 8 Dec 2022 11:43:16 -0600 Subject: [PATCH 2/5] Fixing mypy errors --- azure/functions/_sql.py | 16 ++++++++-------- azure/functions/sql.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/azure/functions/_sql.py b/azure/functions/_sql.py index 3bedfb48..ca7fdf59 100644 --- a/azure/functions/_sql.py +++ b/azure/functions/_sql.py @@ -5,16 +5,16 @@ import json -class SqlRow(abc.ABC): +class BaseSqlRow(abc.ABC): @classmethod @abc.abstractmethod - def from_json(cls, json_data: str) -> 'SqlRow': + def from_json(cls, json_data: str) -> 'BaseSqlRow': pass @classmethod @abc.abstractmethod - def from_dict(cls, dct: dict) -> 'SqlRow': + def from_dict(cls, dct: dict) -> 'BaseSqlRow': pass @abc.abstractmethod @@ -30,23 +30,23 @@ def to_json(self) -> str: pass -class SqlRowList(abc.ABC): +class BaseSqlRowList(abc.ABC): pass -class SqlRow(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()}) @@ -66,6 +66,6 @@ def __repr__(self) -> str: ) -class SqlRowList(SqlRowList, collections.UserList): +class SqlRowList(BaseSqlRowList, collections.UserList): "A ''UserList'' subclass containing a list of :class:'~SqlRow' objects" pass diff --git a/azure/functions/sql.py b/azure/functions/sql.py index 60919c0e..f8288303 100644 --- a/azure/functions/sql.py +++ b/azure/functions/sql.py @@ -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, From 2f03de1482cdbf1ea657d566126f699da07cdcb9 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Thu, 8 Dec 2022 11:56:15 -0600 Subject: [PATCH 3/5] Removing py36 --- .github/workflows/gh-tests-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-tests-ci.yml b/.github/workflows/gh-tests-ci.yml index 2d46f823..e0e7d915 100644 --- a/.github/workflows/gh-tests-ci.yml +++ b/.github/workflows/gh-tests-ci.yml @@ -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 }} From b08055995722e72a43896010cbc4e47299d8879a Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Tue, 24 Jan 2023 13:38:38 -0600 Subject: [PATCH 4/5] Resolving conflicts --- .github/workflows/gh-tests-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-tests-ci.yml b/.github/workflows/gh-tests-ci.yml index e0e7d915..0338ef9a 100644 --- a/.github/workflows/gh-tests-ci.yml +++ b/.github/workflows/gh-tests-ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python_version: [3.7, 3.8, 3.9, "3.10"] + python_version: [3.7, 3.8, 3.9, "3.10", "3.11"] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python_version }} From 8ea6fd1e85e8c77c06c7d6ace62facc212f1870f Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Tue, 24 Jan 2023 13:58:12 -0600 Subject: [PATCH 5/5] Updated abstract class --- azure/functions/_sql.py | 10 +++++----- tests/test_sql.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure/functions/_sql.py b/azure/functions/_sql.py index ca7fdf59..3d70a1a9 100644 --- a/azure/functions/_sql.py +++ b/azure/functions/_sql.py @@ -10,24 +10,24 @@ class BaseSqlRow(abc.ABC): @classmethod @abc.abstractmethod def from_json(cls, json_data: str) -> 'BaseSqlRow': - pass + raise NotImplementedError @classmethod @abc.abstractmethod def from_dict(cls, dct: dict) -> 'BaseSqlRow': - pass + raise NotImplementedError @abc.abstractmethod def __getitem__(self, key): - pass + raise NotImplementedError @abc.abstractmethod def __setitem__(self, key, value): - pass + raise NotImplementedError @abc.abstractmethod def to_json(self) -> str: - pass + raise NotImplementedError class BaseSqlRowList(abc.ABC): diff --git a/tests/test_sql.py b/tests/test_sql.py index 3fcae437..65a11385 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -1,12 +1,12 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import json import unittest import azure.functions as func import azure.functions.sql as sql from azure.functions.meta import Datum -import json class TestSql(unittest.TestCase):