Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(api)!: Make RESTObjectList typing generic#3121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

igorp-collabora
Copy link
Contributor

@igorp-collaboraigorp-collabora commentedFeb 6, 2025
edited
Loading

BREAKING CHANGE: Type narrowing oflist() methods return can become redundant.

Currently the RESTObjectList type hints yielded objects as base RESTObject. However, the ListMixin is now generic and will return the RESTObject subclass based on the RESTManager typing.

Usingtyping.Generic it is possible to make RESTObjectList type hint a specific subclass of the RESTObject.

Iterating overlist() call the ListMixin will now yield the same object class because bothlist andRESTObjectList will have the same type hinted subclass.

Closes#2062

nejch reacted with thumbs up emojinejch reacted with rocket emoji
@igorp-collabora
Copy link
ContributorAuthor

I made this simple python file to check type hints:

importtypingfromgitlab.v4.objectsimportMergeRequestManagerdeftest_list(mang:MergeRequestManager)->None:forminmang.list():typing.reveal_type(m)

When run on main branch the revealed type will be:

typing_rest_list.py:7: note: Revealed type is "gitlab.base.RESTObject"

Using this branch the revealed type will be:

typing_rest_list.py:7: note: Revealed type is "gitlab.v4.objects.merge_requests.MergeRequest"

I believe this is because bothbase.RESTObjectList[base.TObjCls] | list[base.TObjCls] will yieldTObjCls when iterated on. Not sure how much more value the overloads will bring but they can raise a deprecation warning when theget_all is not used.

@codecovCodecov
Copy link

codecovbot commentedFeb 6, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.28%. Comparing base(9040dbe) to head(d290a21).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@##             main    #3121   +/-   ##=======================================  Coverage   97.28%   97.28%           =======================================  Files          97       97             Lines        5975     5976    +1     =======================================+ Hits         5813     5814    +1  Misses        162      162
FlagCoverage Δ
api_func_v483.41% <95.23%> (-0.07%)⬇️
cli_func_v484.50% <95.23%> (+<0.01%)⬆️
unit90.07% <95.23%> (+<0.01%)⬆️

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

Files with missing linesCoverage Δ
gitlab/base.py100.00% <100.00%> (ø)
gitlab/mixins.py91.34% <100.00%> (ø)
gitlab/v4/cli.py91.85% <100.00%> (ø)
gitlab/v4/objects/ldap.py78.26% <100.00%> (ø)
gitlab/v4/objects/merge_requests.py90.25% <100.00%> (ø)
gitlab/v4/objects/milestones.py100.00% <100.00%> (ø)
gitlab/v4/objects/snippets.py100.00% <100.00%> (ø)
gitlab/v4/objects/users.py99.15% <100.00%> (ø)

Copy link
Member

@nejchnejch left a comment

Choose a reason for hiding this comment

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

Thanks@igorp-collabora again! This LGTM.

Could you maybe add a breaking change footer as outlined inhttps://www.conventionalcommits.org/en/v1.0.0/, with a short sentence outlying the return types for list endpoints will now be the real object rather than RESTObject?

This way it should be easier for downstream users to migrate to our new major bump (I'll look at other deprecations in our code and maybe add more breaking changes as well this month).

igorp-collabora reacted with thumbs up emoji
@igorp-collaboraigorp-collabora changed the titlefeat(api): Make RESTObjectList typing genericfeat(api)!: Make RESTObjectList typing genericFeb 7, 2025
BREAKING CHANGE: Type narrowing of `list()` methods return objectsfrom RESTObject to a concrete subclass (for example `MergeRequest`)can become redundant.Currently the RESTObjectList type hints yielded objectsas base RESTObject. However, the ListMixin is now genericand will return the RESTObject subclass based on the RESTManagertyping.Using `typing.Generic` it is possible to make RESTObjectListtype hint a specific subclass of the RESTObject.Iterating over `list()` call the ListMixin will now yieldthe same object class because both `list` and `RESTObjectList`will have the same type hinted subclass.Signed-off-by: Igor Ponomarev <igor.ponomarev@collabora.com>
@igorp-collabora
Copy link
ContributorAuthor

I added the breaking changes footer to the commit message and an exclamation mark to the commit summary.

nejch reacted with thumbs up emoji

@nejchnejchenabled auto-merge (rebase)February 7, 2025 13:02
@nejchnejch merged commitbefba35 intopython-gitlab:mainFeb 7, 2025
16 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nejchnejchnejch approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Type hint on ListMixin.list is too strict
2 participants
@igorp-collabora@nejch

[8]ページ先頭

©2009-2025 Movatter.jp