-
|
I am working with a ProjectBranchManager and getting a list of branches has the return type (RESTObjectList | List[RESTObject]) I would expect (List[ProjectBranch] | None). I'm clearly not understanding the purpose of the ProjectBranchManager. What I do know is that:
Does not work in any IDE auto completion I have worked with, and even using: Also has issues with auto complete. Auto complete likes this but the linters go crazy because the return types do not match. I very much like being able to hit tab or return to autocomplete as it makes coding faster. However my code has to pass linters, snyk, sonaqube and Prisma Cloud scans to be merged and at present it's impossible with the way I am doing things. So the question is what am I doing wrong and how to I do it correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
@bmmcwhirt thanks for the write-up! You're not doing anything wrong, there are simply some limitations with our ListMixin return types (and a few others). The return type depends on the method signature, e.g. whether you use You can do some type narrowing on your own though, this should also already be documented here: See typing for other issues related to typing. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks. If I come up with a good well formatted solution I'll do a fork/pull request for it to be reviewed. |
Beta Was this translation helpful? Give feedback.
@bmmcwhirt thanks for the write-up! You're not doing anything wrong, there are simply some limitations with our ListMixin return types (and a few others).
The return type depends on the method signature, e.g. whether you use
iterator=False(default) for listing, which returns a list. If you useiterator=True, it returns an iterator (RESTObjectList) for more efficient processing (https://python-gitlab.readthedocs.io/en/stable/api-usage.html#pagination). We just haven't taken the time to narrow this down with overloads or some other approach.You can do some type narrowing on your own though, this should also already be documented here:
https://python-gitlab.readthedocs.io/en/stable/api-usa…