Skip to content

fix(repositories): narrow return type of repository_merge_base to dict[str, Any]#3396

Open
bibekmhj wants to merge 2 commits into
python-gitlab:mainfrom
bibekmhj:fix/3390-repository-merge-base-return-type
Open

fix(repositories): narrow return type of repository_merge_base to dict[str, Any]#3396
bibekmhj wants to merge 2 commits into
python-gitlab:mainfrom
bibekmhj:fix/3390-repository-merge-base-return-type

Conversation

@bibekmhj
Copy link
Copy Markdown

Fixes #3390.

The RepositoryMixin.repository_merge_base method was annotated to return
dict[str, Any] | requests.Response, but the call to http_get does not pass
streamed=True or raw=True, and the GitLab /repository/merge_base endpoint
always responds with application/json. Per Gitlab.http_get's implementation
(gitlab/client.py), this means the result is always a parsed dict at runtime,
and the requests.Response branch is unreachable.

This change:

  • narrows the return annotation to dict[str, Any]
  • adds a TYPE_CHECKING-guarded assert isinstance(result, dict) to inform
    the type-checker, matching the existing pattern used in repository_raw_blob
    and repository_archive

No runtime behavior changes. Downstream users no longer need to add
cast() or assert isinstance(...) calls before indexing the result.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.78%. Comparing base (607dddf) to head (19c45e3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3396   +/-   ##
=======================================
  Coverage   95.78%   95.78%           
=======================================
  Files         100      100           
  Lines        6170     6171    +1     
=======================================
+ Hits         5910     5911    +1     
  Misses        260      260           
Flag Coverage Δ
api_func_v4 83.74% <100.00%> (-0.05%) ⬇️
cli_func_v4 78.72% <33.33%> (-0.02%) ⬇️
unit 90.30% <33.33%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/v4/objects/repositories.py 86.20% <100.00%> (+0.16%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines the typing of RepositoryMixin.repository_merge_base to reflect its actual runtime behavior when calling GitLab’s /repository/merge_base endpoint, so downstream users can safely index into the returned JSON without extra casts.

Changes:

  • Narrow repository_merge_base return type from dict[str, Any] | requests.Response to dict[str, Any].
  • Add a TYPE_CHECKING-guarded assert isinstance(result, dict) after the http_get() call to help static type-checkers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gitlab/v4/objects/repositories.py Outdated
@bibekmhj bibekmhj force-pushed the fix/3390-repository-merge-base-return-type branch from b87775b to 19c45e3 Compare May 10, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gitlab.v4.objects.repositories.RepositoryMixin.repository_merge_base should only return dict[str, Any]

2 participants