You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Instance attribute becomes Unknown when type has __getattr__, but pyright handles it correctly #1719
When a class declares an instance attribute with an explicit type annotation, and that type is a class with __getattr__, basedpyright incorrectly reports the attribute as Unknown when accessed. Standard pyright does not have this issue.
The type is explicitly declared, and the assignment is type-checked. There's no code path where the attribute could be anything other than the declared type.
Reproduction
from __future__ importannotationsfromtypingimportTYPE_CHECKING, AnyifTYPE_CHECKING:
fromgitlab.v4.objectsimportProject# Has __getattr__ via RESTObject base classclassHandler:
_project: Project# Explicitly declared typedef__init__(self, project: Project) ->None:
self._project=project# Assignment is type-checkeddefget_project(self) ->Project:
returnself._project# Warning: Return type is unknown
Playground link - uses a simplified example since gitlab isn't available in playground.
Expected Behavior
self._project should have type Project because:
The attribute is explicitly declared as _project: Project
The assignment self._project = project is type-checked to ensure type safety
There's no code path where _project could be anything other than Project
The __getattr__ on Project is irrelevant - it affects attribute access onProject instances, not how other classes store Project as their own attribute.
Actual Behavior
basedpyright reports:
warning: Return type is unknown (reportUnknownVariableType)
Comparison with pyright
Standard pyright (tested with pyright 1.1.x via uv run --with pyright pyright) reports no warnings for the same code.
Environment
basedpyright 1.37.2
Python 3.14
The issue occurs with python-gitlab's Project class, which inherits from RESTObject that has __getattr__(self, name: str) -> Any
Workaround
Using __slots__ on the holder class makes basedpyright correctly recognize the type:
classHandler:
__slots__= ("_project",)
_project: Project# ... now _project is correctly typed as Project
But this shouldn't be necessary - the explicit type declaration should be sufficient.
Playground link - uses a simplified example since gitlab isn't available in playground.
not sure what's going on here... i assume this isn't what you were trying to show:
Reproduction
from __future__ importannotationsfromtypingimportTYPE_CHECKING, AnyifTYPE_CHECKING:
fromgitlab.v4.objectsimportProject# Has __getattr__ via RESTObject base classclassHandler:
_project: Project# Explicitly declared typedef__init__(self, project: Project) ->None:
self._project=project# Assignment is type-checkeddefget_project(self) ->Project:
returnself._project# Warning: Return type is unknown
i'm not sure what was supposed to be in the minimal playground example, but in this example here the issue doesn't seem to be related to the __getattr__, but rather the RepositoryMixin class that Project extends:
# gitlab/v4/objects/repositories.pyifTYPE_CHECKING:
# When running mypy we use these as the base classes_RestObjectBase=gitlab.base.RESTObjectelse:
_RestObjectBase=objectclassRepositoryMixin(_RestObjectBase):
...
it looks like some sort of hack to work around a mypy bug. but this isn't compatible with pyright because the base module cannot be accessed directly from gitlab that way (more info). this causes the _RestObjectBase class to be Unknown, which is whatt's causing your error.
@DetachHead Ok, clear. Thank you for your analysis!
So I see a that just adding a simple import gitlab.base to the type checking block in gitlab/v4/objects/repositories.py does the trick:
# gitlab/v4/objects/repositories.pyifTYPE_CHECKING:
# When running mypy we use these as the base classesimportgitlab.base# Add this line_RestObjectBase=gitlab.base.RESTObjectelse:
_RestObjectBase=objectclassRepositoryMixin(_RestObjectBase):
...
Activity
Standardize gitlab.v4.objects.Project import path across codebase
DetachHead commentedon Feb 7, 2026
this is just because pyright's defaults are less strict than basedpyright's (more info). the same error occurs in pyright if you enable these rules:
not sure what's going on here... i assume this isn't what you were trying to show:
i'm not sure what was supposed to be in the minimal playground example, but in this example here the issue doesn't seem to be related to the
__getattr__, but rather theRepositoryMixinclass thatProjectextends:it looks like some sort of hack to work around a mypy bug. but this isn't compatible with pyright because the
basemodule cannot be accessed directly fromgitlabthat way (more info). this causes the_RestObjectBaseclass to beUnknown, which is whatt's causing your error.i would recommend opening an issue at https://github.com/python-gitlab/python-gitlab.
here's a minimal repro:
janfrederik commentedon Feb 10, 2026
@DetachHead Ok, clear. Thank you for your analysis!
So I see a that just adding a simple
import gitlab.baseto the type checking block ingitlab/v4/objects/repositories.pydoes the trick:I'll file an issue with python-gitlab.