Skip to content

Commit 62da098

Browse files
Sube-pySube-mmcollerek
authored
chore: 🔧 modify All Fields return type (#1445)
Co-authored-by: zhangluguang <z397503810@gmail.com> Co-authored-by: collerek <collerek@gmail.com>
1 parent 8896005 commit 62da098

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ormar/fields/model_fields.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
from typing import Literal # type: ignore
1919
except ImportError: # pragma: no cover
2020
from typing_extensions import Literal # type: ignore
21+
22+
try:
23+
from typing import Self # type: ignore
24+
except ImportError: # pragma: no cover
25+
from typing_extensions import Self # type: ignore
2126

2227

2328
def is_field_nullable(
@@ -65,7 +70,7 @@ class ModelFieldFactory:
6570
_type: Any = None
6671
_sample: Any = None
6772

68-
def __new__(cls, *args: Any, **kwargs: Any) -> BaseField: # type: ignore
73+
def __new__(cls, *args: Any, **kwargs: Any) -> Self: # type: ignore
6974
cls.validate(**kwargs)
7075

7176
default = kwargs.pop("default", None)
@@ -161,7 +166,7 @@ def __new__( # type: ignore # noqa CFQ002
161166
min_length: Optional[int] = None,
162167
regex: Optional[str] = None,
163168
**kwargs: Any
164-
) -> BaseField: # type: ignore
169+
) -> Self: # type: ignore
165170
kwargs = {
166171
**kwargs,
167172
**{
@@ -214,7 +219,7 @@ def __new__( # type: ignore
214219
maximum: Optional[int] = None,
215220
multiple_of: Optional[int] = None,
216221
**kwargs: Any
217-
) -> BaseField:
222+
) -> Self:
218223
autoincrement = kwargs.pop("autoincrement", None)
219224
autoincrement = (
220225
autoincrement
@@ -255,7 +260,7 @@ class Text(ModelFieldFactory, str):
255260
_type = str
256261
_sample = "text"
257262

258-
def __new__(cls, **kwargs: Any) -> BaseField: # type: ignore
263+
def __new__(cls, **kwargs: Any) -> Self: # type: ignore
259264
kwargs = {
260265
**kwargs,
261266
**{
@@ -295,7 +300,7 @@ def __new__( # type: ignore
295300
maximum: Optional[float] = None,
296301
multiple_of: Optional[int] = None,
297302
**kwargs: Any
298-
) -> BaseField:
303+
) -> Self:
299304
kwargs = {
300305
**kwargs,
301306
**{
@@ -361,7 +366,7 @@ class DateTime(ModelFieldFactory, datetime.datetime):
361366

362367
def __new__( # type: ignore # noqa CFQ002
363368
cls, *, timezone: bool = False, **kwargs: Any
364-
) -> BaseField: # type: ignore
369+
) -> Self: # type: ignore
365370
kwargs = {
366371
**kwargs,
367372
**{
@@ -418,7 +423,7 @@ class Time(ModelFieldFactory, datetime.time):
418423

419424
def __new__( # type: ignore # noqa CFQ002
420425
cls, *, timezone: bool = False, **kwargs: Any
421-
) -> BaseField: # type: ignore
426+
) -> Self: # type: ignore
422427
kwargs = {
423428
**kwargs,
424429
**{
@@ -504,7 +509,7 @@ def __new__( # type: ignore # noqa CFQ002
504509
max_length: int,
505510
represent_as_base64_str: bool = False,
506511
**kwargs: Any
507-
) -> BaseField: # type: ignore
512+
) -> Self: # type: ignore
508513
kwargs = {
509514
**kwargs,
510515
**{
@@ -557,7 +562,7 @@ def __new__( # type: ignore
557562
maximum: Optional[int] = None,
558563
multiple_of: Optional[int] = None,
559564
**kwargs: Any
560-
) -> BaseField:
565+
) -> Self:
561566
autoincrement = kwargs.pop("autoincrement", None)
562567
autoincrement = (
563568
autoincrement
@@ -605,7 +610,7 @@ def __new__( # type: ignore
605610
maximum: Optional[int] = None,
606611
multiple_of: Optional[int] = None,
607612
**kwargs: Any
608-
) -> BaseField:
613+
) -> Self:
609614
autoincrement = kwargs.pop("autoincrement", None)
610615
autoincrement = (
611616
autoincrement
@@ -657,7 +662,7 @@ def __new__( # type: ignore # noqa CFQ002
657662
max_digits: Optional[int] = None,
658663
decimal_places: Optional[int] = None,
659664
**kwargs: Any
660-
) -> BaseField:
665+
) -> Self:
661666
kwargs = {
662667
**kwargs,
663668
**{
@@ -721,7 +726,7 @@ class UUID(ModelFieldFactory, uuid.UUID):
721726

722727
def __new__( # type: ignore # noqa CFQ002
723728
cls, *, uuid_format: str = "hex", **kwargs: Any
724-
) -> BaseField:
729+
) -> Self:
725730
kwargs = {
726731
**kwargs,
727732
**{
@@ -766,7 +771,7 @@ class Enum(ModelFieldFactory):
766771

767772
def __new__( # type: ignore # noqa CFQ002
768773
cls, *, enum_class: Type[E], **kwargs: Any
769-
) -> BaseField:
774+
) -> Self:
770775
kwargs = {
771776
**kwargs,
772777
**{

0 commit comments

Comments
 (0)