Skip to content

chore: add type-hints to gitlab/v4/objects/users.py #1515

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2021
Merged

chore: add type-hints to gitlab/v4/objects/users.py #1515

merged 1 commit into from
Oct 6, 2021

Conversation

JohnVillalovos
Copy link
Member

Adding type-hints to gitlab/v4/objects/users.py

@codecov-commenter
Copy link

codecov-commenter commented Jun 13, 2021

Codecov Report

Merging #1515 (51dd98b) into master (85713bb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1515   +/-   ##
=======================================
  Coverage   91.15%   91.16%           
=======================================
  Files          74       74           
  Lines        4172     4176    +4     
=======================================
+ Hits         3803     3807    +4     
  Misses        369      369           
Flag Coverage Δ
cli_func_v4 80.79% <100.00%> (+0.01%) ⬆️
py_func_v4 80.10% <100.00%> (+0.01%) ⬆️
unit 82.35% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
gitlab/v4/objects/users.py 98.29% <100.00%> (+0.03%) ⬆️

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

I just have a question about how this will go if we continue this way for all modules. I haven't looked at alternatives at all so just asking atm.

Comment on lines +326 to +327
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> User:
return cast(User, super().get(id=id, lazy=lazy, **kwargs))
Copy link
Member

Choose a reason for hiding this comment

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

question: I already merged this for projects but now it has me thinking, is there any way to avoid adding all this boilerplate for typing? There will be a lot of these I imagine if as we go module by module, and I guess will need to be copy/pasted for a lot of mixin usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tried and tried again and tried again... But so far I can't figure out a way to do it. If you can figure it out it will be awesome!

There are ways to do it if you return a self object. But since we are returning self._obj_cls() it doesn't seem like things are smart enough to understand that yet. Well at least not mypy

This will help editors and the type-checker in knowing that gl.users.get() returns a User object. Otherwise it will think it returns a RESTObject which isn't as useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you will probably like my idea for handling gl.users.list() even less 😜

At the moment my best solution for that seems to be adding a UserList class or something like that. I haven't figured it out yet but thinking about it.

@JohnVillalovos JohnVillalovos self-assigned this Jun 13, 2021
Adding type-hints to gitlab/v4/objects/users.py
@JohnVillalovos
Copy link
Member Author

@nejch Is there anything else that needs to be done for this to get merged?

@nejch
Copy link
Member

nejch commented Sep 8, 2021

@nejch Is there anything else that needs to be done for this to get merged?

Sorry @JohnVillalovos I never ended up diving into whether we could avoid the extra code in the discussion above. Maybe I could try to find any typed projects that might rely heavily on managers and mixins?

@JohnVillalovos
Copy link
Member Author

Sorry @JohnVillalovos I never ended up diving into whether we could avoid the extra code in the discussion above. Maybe I could try to find any typed projects that might rely heavily on managers and mixins?

Works for me. Would be cool if cleaner solution. So far I haven't been able to figure one out 😟

@JohnVillalovos
Copy link
Member Author

@nejch Curious if you had time to think about this. My thought is that this works but isn't pretty. But sometimes that is what we have to do. And it is only two lines of code.

As the expression says, "Perfect is the enemy of good" 😊

@nejch nejch merged commit 7753fa2 into python-gitlab:master Oct 6, 2021
@nejch
Copy link
Member

nejch commented Oct 6, 2021

@nejch Curious if you had time to think about this. My thought is that this works but isn't pretty. But sometimes that is what we have to do. And it is only two lines of code.

As the expression says, "Perfect is the enemy of good" blush

@JohnVillalovos I also haven't done much in this direction so let's merge :D Yeah, it won't be much to change if we do figure it out.

@JohnVillalovos JohnVillalovos deleted the jlvillal/mypy_v4_obj_users branch January 4, 2022 06:55
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.

3 participants