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 = object
This 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 / reportUnknownVariableType are enabled
Description
In
gitlab/v4/objects/repositories.py, theRepositoryMixinclass uses a conditional base class for type checking:Pyright (and basedpyright) cannot resolve
gitlab.base.RESTObjecthere becauseimport gitlabdoes not makegitlab.baseaccessible 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,
_RestObjectBaseisUnknown, which propagates throughRepositoryMixinand into all classes that inherit it (e.g.Project). This causes spuriousreportUnknownMemberType/reportUnknownVariableTypewarnings for any code usingProjectattributes.Suggested fix
Add an explicit
import gitlab.baseinside theTYPE_CHECKINGblock:This 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.RESTObjectorgitlab.base.RESTManagerinTYPE_CHECKINGblocks would surface them.Context
reportUnknownMemberType/reportUnknownVariableTypeare enabled