ipython / ipython/traitlets

Instance trait type default value confusion

Open
#315 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
653
Forks
217
Avg merge
2d 21h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.