Skip to content

Commit

Permalink
fix: Resolve python client mypy failed in pre-commit (#2884)
Browse files Browse the repository at this point in the history
* fix: Resolve mypy failed in pre-commit

* update make pre-commit

* change pre-commit to directly add tests

* only scan the changed files
  • Loading branch information
ittuann authored May 23, 2024
1 parent 649d2a9 commit 48e136f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion streampipes-client-python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ reformat-all:

.PHONY: pre-commit
pre-commit:
git ls-files -- 'streampipes/**/*' | xargs poetry run pre-commit run --verbose --files
@CHANGED_FILES_PYTHON=$$(git diff --name-only HEAD~1 HEAD -- 'streampipes/**/*' 'tests/**/*'); \
if [ -n "$$CHANGED_FILES_PYTHON" ]; then \
poetry run pre-commit run --verbose --files $$CHANGED_FILES_PYTHON; \
else \
echo "No files changed in 'streampipes' or 'tests' directories."; \
fi

.PHONY: unit-tests
unit-tests:
Expand Down
17 changes: 15 additions & 2 deletions streampipes-client-python/streampipes/endpoint/api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from streampipes.endpoint import APIEndpoint
from streampipes.model.container import Versions
from streampipes.model.container.resource_container import ResourceContainer
from streampipes.model.resource import Version
from streampipes.model.resource.resource import Resource


Expand Down Expand Up @@ -73,6 +74,16 @@ def _container_cls(self) -> Type[ResourceContainer]:

return Versions

@property
def _resource_cls(cls) -> Type[Version]:
"""Returns the class of the resource that are bundled.
Returns
-------
[Version][streampipes.model.resource.Version]
"""
return Version

@property
def _relative_api_path(self) -> Tuple[str, ...]:
"""Defines the relative api path to the DataStream endpoint.
Expand All @@ -99,7 +110,7 @@ def all(self) -> ResourceContainer:
"""
raise NotImplementedError("The `all()` method is not supported by this endpoint.")

def get(self, identifier: str, **kwargs) -> Resource:
def get(self, identifier: str, **kwargs) -> Version:
"""Queries the resource from the API endpoint.
For this endpoint only one resource is available.
Expand All @@ -125,7 +136,9 @@ def get(self, identifier: str, **kwargs) -> Resource:
"Please set 'identifier' to an empty string or 'None'."
)

return super().get(identifier="")
response = self._make_request(request_method=self._parent_client.request_session.get, url=self.build_url())

return self._resource_cls(**response.json())

def post(self, resource: Resource) -> None:
"""Usually, this method allows to create via this endpoint.
Expand Down

0 comments on commit 48e136f

Please sign in to comment.