-
Notifications
You must be signed in to change notification settings - Fork 433
Open
Description
Running pyright
on this code results in an error
"Type[Unknown]" is not a valid exception class
(variable) DoesNotExist: Type[Unknown]
class WidgetModel(Model):
class Meta: # pyright: ignore[reportIncompatibleVariableOverride]
table_name = "widgets"
read_capacity_units = 1
write_capacity_units = 1
id = UnicodeAttribute(hash_key=True)
name = UnicodeAttribute()
WidgetModel.create_table(wait=True)
try:
WidgetModel.get("id")
except WidgetModel.DoesNotExist:
pytest.fail("WidgetModel does not exist")
Perhaps the aliasing of the type name is confusing pyright.
DoesNotExist: Type[DoesNotExist] = DoesNotExist
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
ikonst commentedon Jun 13, 2025
Hmm. I see.
I think the issue is that pyright doesn't like the
DoesNotExist
inType[DoesNotExist]
seemingly self-referential to the variable name.Doing this appears to fix it:
Mind checking it?
https://pyright-play.net/?strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgDRQjEBuxAhgDYD68CxAUGwMb20DOvUACJhivAHJgYAUQAeSXjAAUszsQQwkYFAEoAXGyiGoCPrw5ce-KAFkwAE2L19RoSPGTZ8mLsIkA2gDkwqIS0nIKAQC6UAC8riEe4TDmMCBwzkYm-GzEMqrqNvaOAHTB7mFeUHxQxBmGlDQMzCSKxNocQA
sirianni commentedon Jun 13, 2025
Yes, if I make that change to
models.py
and rerun pyright it seems to pass. Thanks for the quick response!Importing the base
DoesNotExist
as a different name would also likely fix the issue.ikonst commentedon Jun 13, 2025
Let's fix it.
Also, I've created a PR to add pyright to CI: #1276. So far seeing lots of errors.