-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
expose NoUpdate #2800
base: dev
Are you sure you want to change the base?
expose NoUpdate #2800
Conversation
dash/__init__.py
Outdated
@@ -20,6 +20,7 @@ | |||
from .version import __version__ # noqa: F401,E402 | |||
from ._callback_context import callback_context # noqa: F401,E402 | |||
from ._callback import callback, clientside_callback # noqa: F401,E402 | |||
from ._callback import NoUpdate as NoUpdateType # noqa: F401,E402 |
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.
Might be better do rename it inside _callback.py
, otherwise there might be situations where the same thing shows up as either name. I wouldn't consider that a breaking change, this hasn't ever been part of the exposed API.
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.
@KoolADE85 brought up this point as well.
Compare:
type(no_update) # <class 'dash._callback.NoUpdate'>
whereas with None
, it's
type(None) # <class 'NoneType'>
So we should expect (I'm pretty sure):
type(no_update) # <class 'dash.NoUpdateType'>
Which requires renaming the NoUpdate
class.
We'll want this type
to be discoverable & renaming rather than aliasing enables that.
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.
I'd rather it not be postfixed.
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.
@T4rk1n how come?
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.
What we have here is not a type but a class. Since everything is a class in Python it feel meaningless to have a postfix of Type
which it is not.
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.
My main goal here is just to ensure users always use the instance rather than the class in their callbacks. If we were to expose both dash.no_update
and dash.NoUpdate
, then someone looking at dir(dash)
could easily choose the wrong one. But if we have dash.NoUpdateType
instead it would be clear not to use that one.
To my mind type vs class is a minor distinction, particularly since as @ndrezn points out the type()
function returns the class your object is an instance of, and it fits the pattern of None
/ NoneType
. But if you want to do something else to distinguish the no_update
instance from its class that's fine by me, so long as whatever we do makes it clear not to use the class.
I just pushed the minimal possible change in my mind: renaming This does not implement the behavior @ndrezn mentions as it will still be of type Given |
It does not equate to a typed dict, it's a singleton object, the dict representation is for internal use. |
In an attempt to keep the implementation of this PR at a minimum and, if I'm interpreting the conversation correctly up until now, is there any objection to the current state of this PR? |
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.
💃 for me -- thanks for making those changes! Should be quite useful for improving type signatures in Dash apps. @T4rk1n , any lingering comments from you?
I'd rather we fix the cases where using
intead of Think we can add the check like this:
Then change all our checks to |
I agree with this. Specifically, However, such a change seems adjacent to the topic of this PR which is to simply expose the value. I am more than happy to open another PR suggesting this change. |
Expose
NoUpdate
at top-level dash.The primary application is for type hinting, allowing for comprehensive type checking of dash callbacks.
See: #2799
Contributor Checklist
NoUpdate
fromdash._callback