-
Notifications
You must be signed in to change notification settings - Fork 490
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
Fix parsing issues in TextStyle
and *Event
classes
#3551
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,14 +293,14 @@ class DismissibleDismissEvent(ControlEvent): | |
def __init__(self, e: ControlEvent): | ||
super().__init__(e.target, e.name, e.data, e.control, e.page) | ||
d = json.loads(e.data) | ||
self.direction = DismissDirection(d["direction"]) | ||
self.direction: DismissDirection = DismissDirection(d.get("direction")) | ||
|
||
|
||
class DismissibleUpdateEvent(ControlEvent): | ||
def __init__(self, e: ControlEvent): | ||
super().__init__(e.target, e.name, e.data, e.control, e.page) | ||
d = json.loads(e.data) | ||
self.direction = DismissDirection(d["direction"]) | ||
self.progress = d["progress"] | ||
self.reached = d["reached"] | ||
self.previous_reached = d["previous_reached"] | ||
self.direction: DismissDirection = DismissDirection(d.get("direction")) | ||
self.progress: float = d.get("progress") | ||
self.reached: bool = d.get("reached") | ||
Comment on lines
+296
to
+305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Potential issue with default values in DismissibleUpdateEvent Using |
||
self.previous_reached: bool = d.get("previous_reached") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,15 +215,15 @@ def __init__(self, e: ControlEvent): | |
category=DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
self.src_id: float = d["src_id"] | ||
self.x: float = d["x"] | ||
self.y: float = d["y"] | ||
self.src_id: float = d.get("src_id") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider explicitly handling missing keys instead of using The new code introduces additional complexity by using the class DragTargetAcceptEvent(ControlEvent):
def __init__(self, e: ControlEvent):
super().__init__(e.target, e.name, e.data, e.control, e.page)
d = json.loads(e.data)
warn(
f"{self.__class__.__name__} is deprecated since version 0.22.0 "
f"and will be removed in version 0.26.0. Use DragTargetEvent instead.",
category=DeprecationWarning,
stacklevel=2,
)
try:
self.src_id: float = d["src_id"]
self.x: float = d["x"]
self.y: float = d["y"]
except KeyError as key_error:
raise ValueError(f"Missing expected key in data: {key_error}")
class DragTargetEvent(ControlEvent):
def __init__(self, e: ControlEvent):
super().__init__(e.target, e.name, e.data, e.control, e.page)
d = json.loads(e.data)
try:
self.src_id: float = d["src_id"]
self.x: float = d["x"]
self.y: float = d["y"]
except KeyError as key_error:
raise ValueError(f"Missing expected key in data: {key_error}") This maintains simplicity while explicitly handling missing keys, making the code more robust and easier to maintain. |
||
self.x: float = d.get("x") | ||
self.y: float = d.get("y") | ||
|
||
|
||
class DragTargetEvent(ControlEvent): | ||
def __init__(self, e: ControlEvent): | ||
super().__init__(e.target, e.name, e.data, e.control, e.page) | ||
d = json.loads(e.data) | ||
self.src_id: float = d["src_id"] | ||
self.x: float = d["x"] | ||
self.y: float = d["y"] | ||
self.src_id: float = d.get("src_id") | ||
self.x: float = d.get("x") | ||
self.y: float = d.get("y") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential issue with default values in DataColumnSortEvent
Using
d.get()
without default values might cause issues if the keys are not present. Consider providing default values or handlingNone
cases.