ipython / ipython/traitlets

If the default value for Unicode is traitlets.Undefined, then why is it type string when tested? How can you enforce CLI definition of an attribute if it self-massages to ""?

Offen
#732 2 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

The code below shows that even though `x` is never given a value, it is an empty string.

Why do [the docs](https://traitlets.readthedocs.io/en/stable/trait_types.html#traitlets.Unicode) for `Unicode` state `default_value=traitlets.Undefined` yet the type is string when tested?

```python
from traitlets.config import Application
from traitlets import List, Dict, Integer, Unicode

class App(Application):

aliases = {"x": "App.x", "y": "App.y"}
x = Unicode().tag(config=True)
y = Unicode().tag(config=True)

def start(self):
print(f"typex = {type(self.x)} val={self.x}")
print(f"y={self.y}")

if __name__ == "__main__":
App.launch_instance()
```

## Output

```python
typex = val=
y=
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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