ByteString, specifying length for any bytes-like variable

Offen
#997 4 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
python

Rechercherichtung

Es wird keine Datei, kein Test und kein Einstiegspunkt genannt. Beginne damit, das bestehende Typisierungsverhalten von ByteString und verwandte Diskussionen zur Typisierung zu prüfen, und ermittle anschließend, ob sich bytes-ähnliche Typen, feste oder begrenzte Längen und Schreibbarkeit ohne mypy-Fehler darstellen lassen. Als abgeschlossen gilt die Aufgabe, wenn ein abgestimmtes Annotierungsdesign und dokumentiertes Verhalten der Typprüfung vorliegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

topic: feature

This request is a combination of two additions to ByteString that apparently are not supported yet, or at least I could find no discussion of them.

  • Support any bytes-like buffers, not only bytes, bytearray and memoryview
  • Allow specifying the length of the buffer expected (in my case it usually must be exactly 32 bytes)

Ideally, Python typing would allow specifying bytes-like of (a) any length, (b) fixed length or (c) min and/or max length. Potentially also separately specifying if a writable buffer is expected.

While I don't expect for mypy to be able to check for all of that, it would at least be nice to include such information in the annotations for documentation purposes, avoiding the use of docstrings for parameter definitions where names and types are descriptive enough. Is there any way to do this without causing mypy errors, considering that I would rather have no type checking but documentative annotations than what the current implementation can do?

Vorherrschende Sprache
Python
Sterne
1.8k
Forks
302
Ø Merge
23 Std.
Gemergte PRs (30 T.)
8

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/typing

Alle Issues in python/typing

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

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