From 6e92be755abd09f0077e2011332dd77be0bd51ad Mon Sep 17 00:00:00 2001 From: Andrea Cuneo Date: Wed, 27 Mar 2024 12:43:38 +0000 Subject: [PATCH 1/5] ci: add pyright type checker during CI --- .github/workflows/python-tests.yml | 6 +++++ .vscode/settings.json | 4 +--- pyproject.toml | 9 +++++++- src/Artesian/Exceptions.py | 2 +- .../GMEPublicOffers/GMEPublicOfferQuery.py | 22 +++++++++---------- src/Artesian/MarketData/MarketDataService.py | 2 +- .../MarketData/_Dto/ArtesianMetadataFacet.py | 2 +- .../Query/DefaultPartitionStrategy.py | 12 ++++++---- src/Artesian/Query/_Query.py | 2 +- .../Query/_QueryParameters/QueryParameters.py | 2 +- .../ArtesianJsonSerializer.py | 2 +- 11 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index b82edea..8244189 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -36,6 +36,12 @@ jobs: run: | flake8 . + - uses: jordemort/action-pyright@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} # You need this + reporter: github-check # Change reporter. + lib: true + - name: Test Pytest run: | pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a76925..185e2ca 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,11 +2,9 @@ "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, "editor.fontSize": 16, - "python.formatting.provider": "none", - "python.linting.flake8Enabled": true, "editor.formatOnPaste": true, "editor.formatOnSave": true, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" } -} +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index e73fd33..e086c95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -155,4 +155,11 @@ python_files = "Test*.py" testpaths = [ "tests" ] -addopts = "--doctest-modules --junitxml=junit/test-results.xml --cov=src --cov-report=xml --cov-report=html" \ No newline at end of file +addopts = "--doctest-modules --junitxml=junit/test-results.xml --cov=src --cov-report=xml --cov-report=html" + +[tool.pyright] +include = ["src"] +exclude = [ + "**/node_modules", + "**/__pycache__" +] \ No newline at end of file diff --git a/src/Artesian/Exceptions.py b/src/Artesian/Exceptions.py index 3f45b73..19bb376 100644 --- a/src/Artesian/Exceptions.py +++ b/src/Artesian/Exceptions.py @@ -125,7 +125,7 @@ class ArtesianSdkOptimisticConcurrencyException(ArtesianSdkRemoteException): """ def __init__( - self: ArtesianSdkValidationException, + self: ArtesianSdkOptimisticConcurrencyException, method: str, url: str, statusCode: int, diff --git a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py index 599bdac..0879722 100644 --- a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py +++ b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py @@ -222,7 +222,7 @@ async def executeAsync(self: GMEPublicOfferQuery) -> Any: urls = self.__buildRequest() return await self._execAsync(urls) - def __buildRequest(self: GMEPublicOfferQuery) -> str: + def __buildRequest(self: GMEPublicOfferQuery) -> List[str]: self._validateQuery() qp = self._queryParameters urls = [] @@ -352,14 +352,20 @@ def __getMarket(self: GMEPublicOfferQuery, market: Market) -> str: raise Exception("Not supported Market") return vr - def __getPurpose(self: GMEPublicOfferQuery, purpose: Purpose) -> str: + def __getPurpose(self: GMEPublicOfferQuery, purpose: Purpose | None) -> str: + if purpose is None: + raise Exception("Not supported Purpose") + switcher = {Purpose.BID: "BID", Purpose.OFF: "OFF"} vr = switcher.get(purpose, "Defpurp") if vr == "Defpurp": raise Exception("Not supported Purpose") return vr - def __getStatus(self: GMEPublicOfferQuery, status: Status) -> str: + def __getStatus(self: GMEPublicOfferQuery, status: Status | None) -> str: + if status is None: + raise Exception("Not supported Status") + switcher = { Status.ACC: "ACC", Status.INC: "INC", @@ -433,14 +439,6 @@ def _buildExtractionRangeRoute( subPath = f"{self.__toUrlParam(queryParamaters.extractionRangeConfig.date)}" return subPath - def _buildExtractionStatus(self: GMEPublicOfferQuery, status: Status) -> str: - subPath = f"{parse.quote_plus(status)}" - return subPath - - def _buildExtractionPurpose(self: GMEPublicOfferQuery, purpose: Purpose) -> str: - subPath = f"{parse.quote_plus(purpose)}" - return subPath - def _exec(self: GMEPublicOfferQuery, urls: List[str]) -> list: loop = get_event_loop() rr = loop.run_until_complete(self._execAsync(urls)) @@ -453,7 +451,7 @@ async def _execAsync(self: GMEPublicOfferQuery, urls: List[str]) -> list: ) return list(itertools.chain(*res)) - def __toUrlParam(self: GMEPublicOfferQuery, date: str) -> str: + def __toUrlParam(self: GMEPublicOfferQuery, date: str | None) -> str: return f"{date}" def _validateQuery(self: GMEPublicOfferQuery) -> None: diff --git a/src/Artesian/MarketData/MarketDataService.py b/src/Artesian/MarketData/MarketDataService.py index 8b2b49c..bd12848 100644 --- a/src/Artesian/MarketData/MarketDataService.py +++ b/src/Artesian/MarketData/MarketDataService.py @@ -118,7 +118,7 @@ async def searchFacetAsync( self: MarketDataService, page: int, pageSize: int, - searchText: str = None, + searchText: str | None = None, filters: Optional[Dict[str, List[str]]] = None, sorts: Optional[List[str]] = None, doNotLoadAdditionalInfo: bool = False, diff --git a/src/Artesian/MarketData/_Dto/ArtesianMetadataFacet.py b/src/Artesian/MarketData/_Dto/ArtesianMetadataFacet.py index 24804bb..39a07eb 100644 --- a/src/Artesian/MarketData/_Dto/ArtesianMetadataFacet.py +++ b/src/Artesian/MarketData/_Dto/ArtesianMetadataFacet.py @@ -29,5 +29,5 @@ class ArtesianMetadataFacet: """ facetName: Optional[str] = None - facetType: ArtesianMetadataFacetType = None + facetType: Optional[ArtesianMetadataFacetType] = None values: Optional[List[ArtesianMetadataFacetCount]] = None diff --git a/src/Artesian/Query/DefaultPartitionStrategy.py b/src/Artesian/Query/DefaultPartitionStrategy.py index c432920..1ee2b60 100644 --- a/src/Artesian/Query/DefaultPartitionStrategy.py +++ b/src/Artesian/Query/DefaultPartitionStrategy.py @@ -1,6 +1,8 @@ from __future__ import annotations import copy -from typing import List +from typing import List, TypeVar + +from ._QueryParameters.QueryParameters import _QueryParameters from ._QueryParameters.ActualQueryParameters import ActualQueryParameters from ._QueryParameters.VersionedQueryParameters import VersionedQueryParameters from ._QueryParameters.AuctionQueryParameters import AuctionQueryParameters @@ -8,6 +10,8 @@ from ._QueryParameters.BidAskQueryParameters import BidAskQueryParameters +T = TypeVar('T', bound=_QueryParameters) + class DefaultPartitionStrategy: """Class for the default strategy to partition Query Parameters.""" @@ -89,9 +93,9 @@ def PartitionBidAsk( return self._tsPartitionStrategy(bidAskQueryParameters) def _tsPartitionStrategy( - self: DefaultPartitionStrategy, Parameters: List[MasQueryParameters] - ) -> List[MasQueryParameters]: - res: List[MasQueryParameters] = [] + self: DefaultPartitionStrategy, Parameters: List[T] + ) -> List[T]: + res: List[T] = [] for param in Parameters: if param.ids is None: res.append(param) diff --git a/src/Artesian/Query/_Query.py b/src/Artesian/Query/_Query.py index 12cf1b3..f6192f1 100644 --- a/src/Artesian/Query/_Query.py +++ b/src/Artesian/Query/_Query.py @@ -172,7 +172,7 @@ async def _execAsync(self: _Query, urls: List[str]) -> list: ) return list(itertools.chain(*res)) - def __toUrlParam(self: _Query, start: str, end: str) -> str: + def __toUrlParam(self: _Query, start: str | None, end: str | None) -> str: return f"{start}/{end}" def _validateQuery(self: _Query) -> None: diff --git a/src/Artesian/Query/_QueryParameters/QueryParameters.py b/src/Artesian/Query/_QueryParameters/QueryParameters.py index 0dfd3ec..85f4566 100644 --- a/src/Artesian/Query/_QueryParameters/QueryParameters.py +++ b/src/Artesian/Query/_QueryParameters/QueryParameters.py @@ -40,7 +40,7 @@ def getUrlParams(self: _FillCustomTimeserieStrategy) -> str: return f"fillerK=CustomValue&fillerDV={self.val}" -def toQueryParams(vals: List[List[str]]) -> str: +def toQueryParams(vals: List[List[str | float | int | None]]) -> str: filtered = filter(lambda x: x[1], vals) stringVals = map(lambda x: [x[0], str(x[1])], filtered) joinedEqual = map(lambda x: "=".join(x), stringVals) diff --git a/src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py b/src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py index 49c31d1..c51c9bd 100644 --- a/src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py +++ b/src/Artesian/_ClientsExecutor/ArtesianJsonSerializer.py @@ -57,7 +57,7 @@ def __artesianDictDeserializer( obj: list, cls: type, *args: Any, **kwargs: Any ) -> object: key, value = get_args(cls) - result: Dict[key, value] = { + result: Dict[key, value] = { # type: ignore jsons.load(item["Key"], key, *args, **kwargs): jsons.load( item["Value"], value, *args, **kwargs ) From 0df472a9466cdde6155d2365785dd60384f4e06a Mon Sep 17 00:00:00 2001 From: Andrea Cuneo Date: Wed, 27 Mar 2024 12:58:07 +0000 Subject: [PATCH 2/5] chore: fix flake8 errors --- src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py | 1 - src/Artesian/Query/DefaultPartitionStrategy.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py index 0879722..8248eb8 100644 --- a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py +++ b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py @@ -355,7 +355,6 @@ def __getMarket(self: GMEPublicOfferQuery, market: Market) -> str: def __getPurpose(self: GMEPublicOfferQuery, purpose: Purpose | None) -> str: if purpose is None: raise Exception("Not supported Purpose") - switcher = {Purpose.BID: "BID", Purpose.OFF: "OFF"} vr = switcher.get(purpose, "Defpurp") if vr == "Defpurp": diff --git a/src/Artesian/Query/DefaultPartitionStrategy.py b/src/Artesian/Query/DefaultPartitionStrategy.py index 1ee2b60..5795cc7 100644 --- a/src/Artesian/Query/DefaultPartitionStrategy.py +++ b/src/Artesian/Query/DefaultPartitionStrategy.py @@ -10,7 +10,8 @@ from ._QueryParameters.BidAskQueryParameters import BidAskQueryParameters -T = TypeVar('T', bound=_QueryParameters) +T = TypeVar("T", bound=_QueryParameters) + class DefaultPartitionStrategy: """Class for the default strategy to partition Query Parameters.""" From 6a0dff638b9345d60f9452e6a2d7873a09778015 Mon Sep 17 00:00:00 2001 From: Andrea Cuneo Date: Wed, 27 Mar 2024 13:25:52 +0000 Subject: [PATCH 3/5] ci: fix pyright check --- .github/workflows/python-tests.yml | 5 ++--- .vscode/extensions.json | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 8244189..9f63bfc 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -38,9 +38,8 @@ jobs: - uses: jordemort/action-pyright@v1 with: - github_token: ${{ secrets.GITHUB_TOKEN }} # You need this - reporter: github-check # Change reporter. - lib: true + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-check - name: Test Pytest run: | diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0b61104 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-python.flake8", + "github.vscode-github-actions", + "ms-python.vscode-pylance", + "ms-python.python", + "ms-python.debugpy", + "ms-python.black-formatter" + ] +} \ No newline at end of file From 20a8fe3913409243c0cd23038cdb49690e0a4918 Mon Sep 17 00:00:00 2001 From: Andrea Cuneo Date: Wed, 27 Mar 2024 13:31:23 +0000 Subject: [PATCH 4/5] ci: try fix action-pyright --- .github/workflows/python-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 9f63bfc..9ece769 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -39,7 +39,8 @@ jobs: - uses: jordemort/action-pyright@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-check + reporter: github-check + lib: - name: Test Pytest run: | From c69dcd3fe8921f88935244c801a43c84c58db1e6 Mon Sep 17 00:00:00 2001 From: Andrea Cuneo Date: Wed, 27 Mar 2024 13:44:35 +0000 Subject: [PATCH 5/5] ci: fix action-pyright --- .github/workflows/python-tests.yml | 2 ++ src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 9ece769..1a3bd92 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -41,6 +41,8 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-check lib: + level: warning + filter_mode: file - name: Test Pytest run: | diff --git a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py index 12b3f91..1687756 100644 --- a/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py +++ b/src/Artesian/GMEPublicOffers/GMEPublicOfferQuery.py @@ -221,7 +221,7 @@ async def executeAsync(self: GMEPublicOfferQuery) -> Any: url = self.__buildRequest() return await self._execAsync(url) - def __buildRequest(self: GMEPublicOfferQuery) -> List[str]: + def __buildRequest(self: GMEPublicOfferQuery) -> str: self._validateQuery() qp = self._queryParameters