Skip to content

Commit 3407a8b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
1 parent 1a064f3 commit 3407a8b

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

django-stubs/forms/fields.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import json
21
import datetime
2+
import json
33
from collections.abc import Callable, Collection, Iterator, Sequence
44
from decimal import Decimal
55
from re import Pattern
@@ -14,7 +14,7 @@ from django.forms.forms import BaseForm
1414
from django.forms.widgets import Widget
1515
from django.utils.choices import CallableChoiceIterator, _ChoicesCallable, _ChoicesInput
1616
from django.utils.datastructures import _PropertyDescriptor
17-
from django.utils.functional import _StrOrPromise, SimpleLazyObject
17+
from django.utils.functional import SimpleLazyObject, _StrOrPromise
1818
from typing_extensions import Self, override
1919

2020
# Problem: attribute `widget` is always of type `Widget` after field instantiation.
@@ -621,7 +621,12 @@ class JSONField(CharField):
621621
widget: _ClassLevelWidgetT
622622
encoder: type[json.JSONEncoder] | None
623623
decoder: type[json.JSONDecoder] | None
624-
def __init__(self, encoder: type[json.JSONEncoder] | None = None, decoder: type[json.JSONDecoder] | None = None, **kwargs: Any) -> None: ...
624+
def __init__(
625+
self,
626+
encoder: type[json.JSONEncoder] | None = None,
627+
decoder: type[json.JSONDecoder] | None = None,
628+
**kwargs: Any,
629+
) -> None: ...
625630
@override
626631
def to_python(self, value: Any) -> Any: ...
627632
@override
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
from __future__ import annotations
22

33
import json
4-
from typing import Collection
4+
from collections.abc import Collection
5+
56
# Import DateTimeFormatsIterator explicitly from fields module
67
from django.forms import DateField, JSONField
7-
from django.forms.fields import DateTimeFormatsIterator
8+
from django.forms.fields import DateTimeFormatsIterator
89
from typing_extensions import assert_type
910

11+
1012
# 1. Test for BaseTemporalField (via DateField)
1113
def test_temporal_field_input_formats() -> None:
1214
field = DateField(input_formats=["%Y-%m-%d"])
1315
# Verify that input_formats is correctly typed as a Union including DateTimeFormatsIterator
1416
assert_type(field.input_formats, Collection[str] | DateTimeFormatsIterator | None)
1517

18+
1619
# 2. Test for JSONField Encoder/Decoder
1720
class MyEncoder(json.JSONEncoder):
1821
pass
1922

23+
2024
class MyDecoder(json.JSONDecoder):
2125
pass
2226

27+
2328
def test_json_field_serialization_types() -> None:
2429
field = JSONField(encoder=MyEncoder, decoder=MyDecoder)
2530
assert_type(field.encoder, type[json.JSONEncoder] | None)
26-
assert_type(field.decoder, type[json.JSONDecoder] | None)
31+
assert_type(field.decoder, type[json.JSONDecoder] | None)

0 commit comments

Comments
 (0)