Skip to content

Commit 12f3dc5

Browse files
committed
Improved type hints [skip ci]
1 parent c9998e6 commit 12f3dc5

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

pgvector/django/bit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ def db_type(self, connection: Any) -> str:
2222
return 'bit'
2323
return 'bit(%d)' % self.length
2424

25-
def formfield(self, **kwargs: Any) -> forms.Field: # type: ignore
26-
return super().formfield(form_class=BitFormField, **kwargs)
25+
def formfield(self, form_class: Any = None, choices_form_class: Any = None, **kwargs: Any) -> forms.Field:
26+
return super().formfield(
27+
form_class=BitFormField if form_class is None else form_class,
28+
choices_form_class=choices_form_class,
29+
**kwargs
30+
)
2731

2832

2933
class BitFormField(forms.CharField):

pgvector/django/halfvec.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ def get_prep_value(self, value: Any) -> str | None:
4141
def value_to_string(self, obj: Any) -> str | None:
4242
return self.get_prep_value(self.value_from_object(obj))
4343

44-
def formfield(self, **kwargs) -> forms.Field: # type: ignore
45-
return super().formfield(form_class=HalfVectorFormField, **kwargs)
44+
def formfield(self, form_class: Any = None, choices_form_class: Any = None, **kwargs: Any) -> forms.Field:
45+
return super().formfield(
46+
form_class=HalfVectorFormField if form_class is None else form_class,
47+
choices_form_class=choices_form_class,
48+
**kwargs
49+
)
4650

4751

4852
class HalfVectorWidget(forms.TextInput):

pgvector/django/sparsevec.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def get_prep_value(self, value: Any) -> str | None:
3636
def value_to_string(self, obj: Any) -> str | None:
3737
return self.get_prep_value(self.value_from_object(obj))
3838

39-
def formfield(self, **kwargs: Any) -> forms.Field: # type: ignore
40-
return super().formfield(form_class=SparseVectorFormField, **kwargs)
39+
def formfield(self, form_class: Any = None, choices_form_class: Any = None, **kwargs: Any) -> forms.Field:
40+
return super().formfield(
41+
form_class=SparseVectorFormField if form_class is None else form_class,
42+
choices_form_class=choices_form_class,
43+
**kwargs
44+
)
4145

4246

4347
class SparseVectorWidget(forms.TextInput):

pgvector/django/vector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def run_validators(self, value: Any) -> None:
4949
value = value.tolist()
5050
super().run_validators(value)
5151

52-
def formfield(self, **kwargs: Any) -> forms.Field: # type: ignore
53-
return super().formfield(form_class=VectorFormField, **kwargs)
52+
def formfield(self, form_class: Any = None, choices_form_class: Any = None, **kwargs: Any) -> forms.Field:
53+
return super().formfield(
54+
form_class=VectorFormField if form_class is None else form_class,
55+
choices_form_class=choices_form_class,
56+
**kwargs
57+
)
5458

5559

5660
class VectorWidget(forms.TextInput):

0 commit comments

Comments
 (0)