Skip to content

fix(types): add explicit submodule import for pyright compatibility#3343

Merged
nejch merged 1 commit intopython-gitlab:mainfrom
janfrederik:fix/pyright-implicit-submodule-access
Feb 16, 2026
Merged

fix(types): add explicit submodule import for pyright compatibility#3343
nejch merged 1 commit intopython-gitlab:mainfrom
janfrederik:fix/pyright-implicit-submodule-access

Conversation

@janfrederik
Copy link
Contributor

@janfrederik janfrederik commented Feb 10, 2026

Summary

  • Add import gitlab.base inside the TYPE_CHECKING block in repositories.py so that pyright can resolve gitlab.base.RESTObject

Without the explicit import, pyright cannot resolve the submodule access via the parent package — implicit submodule access is a runtime loader side effect that type checkers don't model (pyright docs). This causes _RestObjectBase to be Unknown, which propagates through RepositoryMixin into Project and other classes that inherit it, producing reportUnknownMemberType / reportUnknownVariableType / reportUnknownArgumentType warnings.

Note: gitlab/mixins.py has the same pattern but already works correctly because it uses from gitlab import base and then base.RESTObject.

Fixes #3342

Test plan

  • Verified with basedpyright on a real project: previously-required # pyright: ignore suppression comments become unnecessary after this fix
  • Existing CI tests pass (no runtime impact — change is inside TYPE_CHECKING block only)

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.

Thanks for this @janfrederik.

Admittedly this piece of code is a bit awkward to begin with - we might not really need a mixin in there, it was mostly to separate out the repository-related methods for projects.

Add `import gitlab.base` inside the TYPE_CHECKING block in
repositories.py so that pyright can resolve `gitlab.base.RESTObject`.

Without the explicit import, pyright cannot resolve the submodule
access via the parent package (implicit submodule access is a runtime
loader side effect that type checkers don't model). This caused
`_RestObjectBase` to be `Unknown`, propagating through `RepositoryMixin`
into `Project` and other classes.

Fixes python-gitlab#3342

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@nejch nejch force-pushed the fix/pyright-implicit-submodule-access branch from 02c1e9d to 8c27f9b Compare February 16, 2026 10:00
@nejch nejch enabled auto-merge (rebase) February 16, 2026 10:05
@nejch nejch merged commit 84ad3fd into python-gitlab:main Feb 16, 2026
16 checks passed
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.

RepositoryMixin base class unresolvable by pyright due to implicit submodule access

2 participants