ipython / ipython/traitlets

Instance trait type default value confusion

Offen
#315 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
653
Forks
217
Ø Merge
2 T. 21 Std.
Gemergte PRs (30 T.)
2

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.