ipython / ipython/traitlets

Instance trait type default value confusion

未关闭
#315 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
653
派生
217
平均合并
2 天 21 小时
30 天内合并 PR
2

描述

We raise here:

``` python
class A(HasTraits):
inst = Instance(Foo)

A().inst
```

But not here:

``` python
class A(HasTraits):
inst = Instance(Foo, allow_none=True)

A().inst
```

This seems magical, and is not at all implied by `allow_none=True`.

We should probably try to enforce this convention:

``` python
class A(HasTraits):
inst = Instance(Foo, default_value=None, allow_none=True)

A().inst
```

Or at the very least:

set `allow_none=True` if `default_value=None`

``` python
class A(HasTraits):
inst = Instance(Foo, default_value=None)

A().inst
```

This isn't backwards compatible, but IMO it resolves a bug.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。