Skip to content

Commit

Permalink
Merge branch 'dev' into fix-mypy-issues-service-dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
khoaguin committed Feb 14, 2024
2 parents e539703 + 034cd96 commit 1183f9d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ repos:
- id: mypy
name: "mypy: syft"
always_run: true
files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/dataset"
files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/warnings.py|^packages/syft/src/syft/service/dataset"
#files: "^packages/syft/src/syft/serde"
args: [
"--follow-imports=skip",
Expand Down
100 changes: 50 additions & 50 deletions packages/syft/src/syft/service/warnings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# stdlib
from typing import Any
from typing import Optional

# third party
Expand Down Expand Up @@ -30,7 +31,7 @@ class APIEndpointWarning(SyftBaseModel):
message: Optional[str] = None
enabled: bool = True

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, APIEndpointWarning):
return self.message == other.message and self._bool == other._bool
return self._bool == other
Expand All @@ -54,7 +55,7 @@ def _repr_html_(self) -> str:
def message_from(self, context: Optional[WarningContext]) -> Self:
raise NotImplementedError

def show(self):
def show(self) -> bool:
if not self.enabled or not self.message:
return True
display(self)
Expand All @@ -68,24 +69,24 @@ def show(self):

@serializable()
class CRUDWarning(APIEndpointWarning):
def message_from(self, context: Optional[WarningContext] = None):
def message_from(self, context: Optional[WarningContext] = None) -> Self:
message = None
confirmation = self.confirmation
if context is not None:
node = context.node
node_side_type = node.node_side_type
node_type = node.node_type
_msg = (
"which could host datasets with private information."
if node_side_type.value == NodeSideType.HIGH_SIDE.value
else "which only hosts mock or synthetic data."
)
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value}, {_msg}"
)
confirmation = node_side_type.value == NodeSideType.HIGH_SIDE.value
message = message
if node is not None:
node_side_type = node.node_side_type
node_type = node.node_type
_msg = (
"which could host datasets with private information."
if node_side_type.value == NodeSideType.HIGH_SIDE.value
else "which only hosts mock or synthetic data."
)
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value}, {_msg}"
)
confirmation = node_side_type.value == NodeSideType.HIGH_SIDE.value

return CRUDWarning(confirmation=confirmation, message=message)

Expand All @@ -94,63 +95,62 @@ def message_from(self, context: Optional[WarningContext] = None):
class CRUDReminder(CRUDWarning):
confirmation: bool = False

def message_from(self, context: Optional[WarningContext] = None):
def message_from(self, context: Optional[WarningContext] = None) -> Self:
message = None
confirmation = self.confirmation
if context is not None:
node = context.node
node_side_type = node.node_side_type
node_type = node.node_type
_msg = (
"which could host datasets with private information."
if node_side_type.value == NodeSideType.HIGH_SIDE.value
else "which only hosts mock or synthetic data."
)
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value}, {_msg}"
)
message = message
if node is not None:
node_side_type = node.node_side_type
node_type = node.node_type
_msg = (
"which could host datasets with private information."
if node_side_type.value == NodeSideType.HIGH_SIDE.value
else "which only hosts mock or synthetic data."
)
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value}, {_msg}"
)

return CRUDReminder(confirmation=confirmation, message=message)


@serializable()
class LowSideCRUDWarning(APIEndpointWarning):
def message_from(self, context: Optional[WarningContext] = None):
def message_from(self, context: Optional[WarningContext] = None) -> Self:
confirmation = self.confirmation
message = None
if context is not None:
node = context.node
node_side_type = node.node_side_type
node_type = node.node_type
if node_side_type.value == NodeSideType.LOW_SIDE.value:
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value} "
"which only hosts mock or synthetic data."
)

message = message
if node is not None:
node_side_type = node.node_side_type
node_type = node.node_type
if node_side_type.value == NodeSideType.LOW_SIDE.value:
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value} "
"which only hosts mock or synthetic data."
)

return LowSideCRUDWarning(confirmation=confirmation, message=message)


@serializable()
class HighSideCRUDWarning(APIEndpointWarning):
def message_from(self, context: Optional[WarningContext] = None):
def message_from(self, context: Optional[WarningContext] = None) -> Self:
confirmation = self.confirmation
message = None
if context is not None:
node = context.node
node_side_type = node.node_side_type
node_type = node.node_type
if node_side_type.value == NodeSideType.HIGH_SIDE.value:
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value} "
"which could host datasets with private information."
)
message = message
if node is not None:
node_side_type = node.node_side_type
node_type = node.node_type
if node_side_type.value == NodeSideType.HIGH_SIDE.value:
message = (
"You're performing an operation on "
f"{node_side_type.value} side {node_type.value} "
"which could host datasets with private information."
)

return HighSideCRUDWarning(confirmation=confirmation, message=message)

0 comments on commit 1183f9d

Please sign in to comment.