enthought / enthought/traits

_default() methods only call functions, instancemethods

Open
#230 1 comment 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Reported by @rdgraham at enthought/traitsui#193. Original report follows.

I have noticed that if a define a _name_default() for a given trait in a traitsUI class, it only seems to be called if it is a method defined inline with `def` or a lambda. I may be misunderstanding something but it seems to me that any callable object should work.

For example I have a class SettingsLoader which defines a `__call__` method and deals with loading default values in some cases. Wrapping it in a lambda expression works but I don't know why that is necessary. eg:

``` python
class A(HasTraits):
foo = String('')
_foo_default = lambda self : SettingsLoader('foo')()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.