adafruit / adafruit/Adafruit_CircuitPython_Typing
Improve `{Readable, WriteableBuffer}Buffer`
- Dominant language
- Python
- Stars
- 7
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Right now, there is code using `len()` on variables hinted as such types. However, this is not correct with the current implementation of hints due to the lack of `Sized`.
I believe they should be slightly changed like this, such that the type correctly marks the existence of `__len__(self) -> int`
```py
ReadableBuffer: TypeAlias = TypeVar(
"ReadableBuffer",
Sized,
bound=Union[
array.array,
bytearray,
bytes,
memoryview,
"rgbmatrix.RGBMatrix",
"ulab.numpy.ndarray",
],
)
```
But im not sure about this syntax, as im not a typing expert, would love some feedback before raising a PR. Thanks in advance :)
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the definitions of ReadableBuffer and WriteableBuffer and review how their current TypeVar bounds are used with len(). Check the proposed Sized constraint against the supported typing syntax and existing annotations. Done means the aliases accurately expose __len__(self) -> int without breaking their listed buffer types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100