ipython / ipython/traitlets

traitlets.Set should support generic type annotations for type safety

Đang mở
#927 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
653
Fork
217
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
2

Mô tả

## 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.