Skip to content

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

Open
janfrederik wants to merge 1 commit intopython-gitlab:mainfrom
janfrederik:fix/pyright-implicit-submodule-access
Open

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

Conversation

@janfrederik
Copy link

@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)

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]>
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

1 participant