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 — assert_never raises different exception than documented · Issue #1857 · gitpython-developers/GitPython

assert_never raises different exception than documented #1857

New issue
Copy link
New issue
Copy link
Closed
#1859
Closed
assert_never raises different exception than documented#1857
#1859
Copy link
Labels
acknowledgedhelp wanted

Description

@EliahKagan
EliahKagan
opened on Mar 4, 2024
Issue body actions

git.types.assert_never is documented to raise AssertionError if raise_error is True and exc is None:

GitPython/git/types.py

Line 83 in b2c3d8b

If raise_error is True, will also raise AssertionError or the Exception passed to exc.

But it actually raises ValueError in this situation, its full implementation being:

GitPython/git/types.py

Lines 85 to 89 in b2c3d8b

if raise_error:
if exc is None:
raise ValueError(f"An unhandled Literal ({inp}) in an if/else chain was found")
else:
raise exc

For comparison. there is an assert_never function in Python's typing module since 3.11 (and in typing_extensions). This function is similar but only has one parameter--which the first parameter of git.types.assert_never corresponds to--and it documents that it raises an exception if called at runtime, but does not document the type of exception raised. At least currently in Python 3.12, it raises AssertionError.

The GitPython function is a public member of git.types, and it is used internally in GitPython. I don't know if the docstring should be fixed to describe the existing behavior, or if that behavior should itself be considered the bug here and changed to match the docstring.

Activity

  1. Byron
    added
    acknowledged
    help wanted
    on Mar 5, 2024
  2. Byron commented on Mar 5, 2024

    @Byron
    Byron
    on Mar 5, 2024
    Member
    More actions

    Thanks for letting me know.

    It does seem a bit strange to me that functions related to testing are part of the git public API in the first place, but it's probably nothing that can truly be fixed anymore.

    With that said, even tough there mere existence could be considered a bug, I tend to leave it and its behaviour alone while fixing the docstring.

  3. Byron
    closed this as completedin #1859on Mar 14, 2024
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

    acknowledgedhelp wanted

    Type

    No type

    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.