GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ByteString, specifying length for any bytes-like variable · Issue #997 · python/typing

ByteString, specifying length for any bytes-like variable #997

New issue
Copy link
New issue
Copy link
Open
Open
ByteString, specifying length for any bytes-like variable#997
Copy link
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations

Description

@covert-encryption
covert-encryption
opened on Dec 31, 2021
Issue body actions

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?

Reacted by Max Chernoff and STEHLE-hermle

Activity

  1. covert-encryption
    added
    topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
    on Dec 31, 2021
  2. hauntsaninja commented on Dec 31, 2021

    @hauntsaninja
    hauntsaninja
    on Dec 31, 2021
    Collaborator
    More actions

    Seems like a good use for PEP 593 Annotated.

    Reacted by Alex Waygood
  3. srittau commented on Jan 2, 2022

    @srittau
    srittau
    on Jan 2, 2022
    Collaborator
    More actions

    Duplicate of #593.

  4. srittau
    closed this as completedon Jan 2, 2022
  5. James-E-A commented on Feb 11, 2025

    @James-E-A
    James-E-A
    on Feb 11, 2025
    More actions

    @srittau Are you sure this issue is a duplicate of that one?

    • 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)

    PEP 688 doesn't even contain the word “length”.

  6. srittau commented on Feb 12, 2025

    @srittau
    srittau
    on Feb 12, 2025
    Collaborator
    More actions

    Thanks, I seem to have misunderstood the suggestion.

  7. srittau
    reopened this on Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.