|
18 | 18 | from typing import Literal # type: ignore
|
19 | 19 | except ImportError: # pragma: no cover
|
20 | 20 | 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 |
21 | 26 |
|
22 | 27 |
|
23 | 28 | def is_field_nullable(
|
@@ -65,7 +70,7 @@ class ModelFieldFactory:
|
65 | 70 | _type: Any = None
|
66 | 71 | _sample: Any = None
|
67 | 72 |
|
68 |
| - def __new__(cls, *args: Any, **kwargs: Any) -> BaseField: # type: ignore |
| 73 | + def __new__(cls, *args: Any, **kwargs: Any) -> Self: # type: ignore |
69 | 74 | cls.validate(**kwargs)
|
70 | 75 |
|
71 | 76 | default = kwargs.pop("default", None)
|
@@ -161,7 +166,7 @@ def __new__( # type: ignore # noqa CFQ002
|
161 | 166 | min_length: Optional[int] = None,
|
162 | 167 | regex: Optional[str] = None,
|
163 | 168 | **kwargs: Any
|
164 |
| - ) -> BaseField: # type: ignore |
| 169 | + ) -> Self: # type: ignore |
165 | 170 | kwargs = {
|
166 | 171 | **kwargs,
|
167 | 172 | **{
|
@@ -214,7 +219,7 @@ def __new__( # type: ignore
|
214 | 219 | maximum: Optional[int] = None,
|
215 | 220 | multiple_of: Optional[int] = None,
|
216 | 221 | **kwargs: Any
|
217 |
| - ) -> BaseField: |
| 222 | + ) -> Self: |
218 | 223 | autoincrement = kwargs.pop("autoincrement", None)
|
219 | 224 | autoincrement = (
|
220 | 225 | autoincrement
|
@@ -255,7 +260,7 @@ class Text(ModelFieldFactory, str):
|
255 | 260 | _type = str
|
256 | 261 | _sample = "text"
|
257 | 262 |
|
258 |
| - def __new__(cls, **kwargs: Any) -> BaseField: # type: ignore |
| 263 | + def __new__(cls, **kwargs: Any) -> Self: # type: ignore |
259 | 264 | kwargs = {
|
260 | 265 | **kwargs,
|
261 | 266 | **{
|
@@ -295,7 +300,7 @@ def __new__( # type: ignore
|
295 | 300 | maximum: Optional[float] = None,
|
296 | 301 | multiple_of: Optional[int] = None,
|
297 | 302 | **kwargs: Any
|
298 |
| - ) -> BaseField: |
| 303 | + ) -> Self: |
299 | 304 | kwargs = {
|
300 | 305 | **kwargs,
|
301 | 306 | **{
|
@@ -361,7 +366,7 @@ class DateTime(ModelFieldFactory, datetime.datetime):
|
361 | 366 |
|
362 | 367 | def __new__( # type: ignore # noqa CFQ002
|
363 | 368 | cls, *, timezone: bool = False, **kwargs: Any
|
364 |
| - ) -> BaseField: # type: ignore |
| 369 | + ) -> Self: # type: ignore |
365 | 370 | kwargs = {
|
366 | 371 | **kwargs,
|
367 | 372 | **{
|
@@ -418,7 +423,7 @@ class Time(ModelFieldFactory, datetime.time):
|
418 | 423 |
|
419 | 424 | def __new__( # type: ignore # noqa CFQ002
|
420 | 425 | cls, *, timezone: bool = False, **kwargs: Any
|
421 |
| - ) -> BaseField: # type: ignore |
| 426 | + ) -> Self: # type: ignore |
422 | 427 | kwargs = {
|
423 | 428 | **kwargs,
|
424 | 429 | **{
|
@@ -504,7 +509,7 @@ def __new__( # type: ignore # noqa CFQ002
|
504 | 509 | max_length: int,
|
505 | 510 | represent_as_base64_str: bool = False,
|
506 | 511 | **kwargs: Any
|
507 |
| - ) -> BaseField: # type: ignore |
| 512 | + ) -> Self: # type: ignore |
508 | 513 | kwargs = {
|
509 | 514 | **kwargs,
|
510 | 515 | **{
|
@@ -557,7 +562,7 @@ def __new__( # type: ignore
|
557 | 562 | maximum: Optional[int] = None,
|
558 | 563 | multiple_of: Optional[int] = None,
|
559 | 564 | **kwargs: Any
|
560 |
| - ) -> BaseField: |
| 565 | + ) -> Self: |
561 | 566 | autoincrement = kwargs.pop("autoincrement", None)
|
562 | 567 | autoincrement = (
|
563 | 568 | autoincrement
|
@@ -605,7 +610,7 @@ def __new__( # type: ignore
|
605 | 610 | maximum: Optional[int] = None,
|
606 | 611 | multiple_of: Optional[int] = None,
|
607 | 612 | **kwargs: Any
|
608 |
| - ) -> BaseField: |
| 613 | + ) -> Self: |
609 | 614 | autoincrement = kwargs.pop("autoincrement", None)
|
610 | 615 | autoincrement = (
|
611 | 616 | autoincrement
|
@@ -657,7 +662,7 @@ def __new__( # type: ignore # noqa CFQ002
|
657 | 662 | max_digits: Optional[int] = None,
|
658 | 663 | decimal_places: Optional[int] = None,
|
659 | 664 | **kwargs: Any
|
660 |
| - ) -> BaseField: |
| 665 | + ) -> Self: |
661 | 666 | kwargs = {
|
662 | 667 | **kwargs,
|
663 | 668 | **{
|
@@ -721,7 +726,7 @@ class UUID(ModelFieldFactory, uuid.UUID):
|
721 | 726 |
|
722 | 727 | def __new__( # type: ignore # noqa CFQ002
|
723 | 728 | cls, *, uuid_format: str = "hex", **kwargs: Any
|
724 |
| - ) -> BaseField: |
| 729 | + ) -> Self: |
725 | 730 | kwargs = {
|
726 | 731 | **kwargs,
|
727 | 732 | **{
|
@@ -766,7 +771,7 @@ class Enum(ModelFieldFactory):
|
766 | 771 |
|
767 | 772 | def __new__( # type: ignore # noqa CFQ002
|
768 | 773 | cls, *, enum_class: Type[E], **kwargs: Any
|
769 |
| - ) -> BaseField: |
| 774 | + ) -> Self: |
770 | 775 | kwargs = {
|
771 | 776 | **kwargs,
|
772 | 777 | **{
|
|
0 commit comments