-
Notifications
You must be signed in to change notification settings - Fork 676
Description
Description
In gitlab/v4/objects/repositories.py, the RepositoryMixin class uses a conditional base class for type checking:
import gitlab
if TYPE_CHECKING:
_RestObjectBase = gitlab.base.RESTObject
else:
_RestObjectBase = object
class RepositoryMixin(_RestObjectBase):
...Pyright (and basedpyright) cannot resolve gitlab.base.RESTObject here because import gitlab does not make gitlab.base accessible as an attribute — Python only guarantees submodule access after an explicit import of that submodule. This is a runtime side effect of the import system that type checkers (correctly) don't model. See pyright docs on implicit submodule access.
As a result, _RestObjectBase is Unknown, which propagates through RepositoryMixin and into all classes that inherit it (e.g. Project). This causes spurious reportUnknownMemberType / reportUnknownVariableType warnings for any code using Project attributes.
Suggested fix
Add an explicit import gitlab.base inside the TYPE_CHECKING block:
if TYPE_CHECKING:
import gitlab.base
_RestObjectBase = gitlab.base.RESTObject
else:
_RestObjectBase = objectThis is a one-line change with no runtime impact (it's only evaluated by type checkers).
The same pattern may exist in other files — a quick search for gitlab.base.RESTObject or gitlab.base.RESTManager in TYPE_CHECKING blocks would surface them.
Context
- Discovered via basedpyright#1719
- Affects pyright as well when
reportUnknownMemberType/reportUnknownVariableTypeare enabled