- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Add a default value parameter to get_value() #74
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
Changes from 1 commit
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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -41,16 +41,23 @@ def panel_id(self) -> str: | |
| """Read-only accessor for the panel ID.""" | ||
| return self._panel_id | ||
| 
     | 
||
| def get_value(self, value_id: str) -> object: | ||
| """Get the value for a control on the panel. | ||
| def get_value(self, value_id: str, default_value: object = None) -> object: | ||
| 
         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. Do we want the default value to affect type inference? _T = TypeVar("_T")
@overload
def get_value(self, value_id: str) -> object: ...
@overload
def get_value(self, value_id: str, default_value: _T | None = None) -> _T: ...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. Also see how the stdlib does it: https://github.com/python/typeshed/blob/main/stdlib/typing.pyi#L745  | 
||
| """Get the value for a control on the panel with an optional default value. | ||
| 
     | 
||
| Args: | ||
| value_id: The id of the value | ||
| default_value: The default value to return if the value is not set | ||
| 
     | 
||
| Returns: | ||
| The value | ||
| The value, or the default value if not set | ||
| """ | ||
| return self._panel_client.get_value(self._panel_id, value_id) | ||
| try: | ||
| return self._panel_client.get_value(self._panel_id, value_id) | ||
| except grpc.RpcError as e: | ||
| if e.code() == grpc.StatusCode.NOT_FOUND and default_value is not None: | ||
| return default_value | ||
| else: | ||
| raise e | ||
| 
     | 
||
| def set_value(self, value_id: str, value: object) -> None: | ||
| """Set the value for a control on the panel. | ||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.