Skip to content
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

Add a callable traitlet type #321

Closed
yuvipanda opened this issue Sep 22, 2016 · 4 comments · Fixed by #333
Closed

Add a callable traitlet type #321

yuvipanda opened this issue Sep 22, 2016 · 4 comments · Fixed by #333

Comments

@yuvipanda
Copy link

This would be useful when you need to pass in a function. I've run into this several times when writing JupyterHub spawners. Environment variables can be specified as a dict whose value can be callable in JupyterHub, for example. I'm implementing this in one of my spawners just now, and think it'll be useful in the core library too.

Would people be open to a patch that added a callable traitlet type? if so, should it support further validation? The only one I could think of that'll make sense in Python would be an arity check...

@yuvipanda
Copy link
Author

I actually instead solved it like jupyterhub/systemdspawner@8d9fbc8 instead, which exposed a much smaller customization surface. This helps a lot when maintaining backwards compatibility, so perhaps not having a callable is a good idea! :)

@minrk
Copy link
Member

minrk commented Sep 22, 2016

I'd be fine adding callable. It's also achievable with Any + validation:

class C(HasTraits):
    f = Any()
    @validate('f')
    def _(self, proposal):
        if not callable(proposal.value):
            raise TraitError("I need a callable!")
        return proposal.value

@twavv
Copy link
Contributor

twavv commented May 3, 2018

Seems that the Callable trait isn't available in traitlets via pypi nor is it detailed in the documentation. Is that an oversight and/or is there any way to rectify that?

danielballan added a commit to danielballan/traitlets that referenced this issue May 22, 2019
@danielballan
Copy link
Contributor

I added it to the docs here #523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants