ipython / ipython/traitlets

traitlets.Set should support generic type annotations for type safety

Ouverte
#927 0 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
653
Forks
217
Merge moyen
2 j 21 h
PR mergées (30 j)
2

Description

## Problem

`traitlets.Set` currently lacks generic type support, making it impossible to specify the type of elements it contains for proper type checking.

## Current Situation

```python
from traitlets import Set
import traitlets

class MyClass(traitlets.HasTraits):
# This works but provides no type information
my_set = Set()

# This doesn't work - no generic support
# my_set: Set[str] = Set() # Type error
```

## Desired Behavior

`traitlets.Set` should support generic type annotations similar to how Python's built-in collections work:

```python
from traitlets import Set
import traitlets

class MyClass(traitlets.HasTraits):
# Should be possible for type safety
room_ids: Set[str] = Set()
numbers: Set[int] = Set(default_value={1, 2, 3})
```

## Reference

The `Set` class is implemented in [`traitlets/traitlets.py`](https://github.com/ipython/traitlets/blob/main/traitlets/traitlets.py) as a container trait.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start in traitlets/traitlets.py at the Set container trait implementation and inspect how its type parameters could correspond to the annotated element type. Done means Set accepts annotations such as Set[str] and Set[int] while preserving the existing default-value behavior; the issue does not name a test file or test entry point.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.