Skip to content

Commit 5639987

Browse files
bckohan-botclaude
authored andcommitted
fix pyright type errors for Django version compatibility
- Use getattr() for ChoicesMeta to avoid static attr access on Django 5.0+ stubs - Suppress call-arg errors on CheckConstraint(check=...) backward-compat branches (Django < 5.1) - Suppress attr-defined error on connection.operators which is untyped in Django stubs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f61bfb4 commit 5639987

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/django_enum/choices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ChoicesType = (
2626
model_enums.ChoicesType
2727
if django_version[0:2] >= (5, 0)
28-
else model_enums.ChoicesMeta
28+
else getattr(model_enums, "ChoicesMeta") # removed in Django 5.0
2929
)
3030

3131
DEFAULT_BOUNDARY = getattr(enum, "KEEP", None)

src/django_enum/fields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ def contribute_to_class(
787787
constraint |= Q(**{f"{self.name or name}__isnull": True})
788788
cls._meta.constraints = [
789789
*cls._meta.constraints,
790-
CheckConstraint(
791-
check=constraint,
790+
CheckConstraint( # type: ignore[call-arg]
791+
check=constraint, # type: ignore[call-arg]
792792
name=self.constraint_name(cls, self.name or name, self.enum),
793793
)
794794
if django_version[0:2] < (5, 1)
@@ -1254,8 +1254,8 @@ def contribute_to_class(
12541254

12551255
cls._meta.constraints = [
12561256
*cls._meta.constraints,
1257-
CheckConstraint(
1258-
check=constraint,
1257+
CheckConstraint( # type: ignore[call-arg]
1258+
check=constraint, # type: ignore[call-arg]
12591259
name=self.constraint_name(cls, self.name or name, self.enum),
12601260
)
12611261
if django_version[0:2] < (5, 1)

src/django_enum/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def process_lhs(self, compiler, connection, lhs=None):
2727
return lhs_sql, lhs_params
2828

2929
def get_rhs_op(self, connection, rhs):
30-
return connection.operators["exact"] % rhs
30+
return connection.operators["exact"] % rhs # type: ignore[attr-defined]
3131

3232

3333
# class ExtraBigFlagMixin:

0 commit comments

Comments
 (0)