@@ -456,13 +456,13 @@ class AnyUrl(_BaseUrl):
456
456
457
457
* Any scheme allowed
458
458
* Top-level domain (TLD) not required
459
- * Host required
459
+ * Host not required
460
460
461
461
Assuming an input URL of `http://samuel:pass@example.com:8000/the/path/?query=here#fragment=is;this=bit`,
462
462
the types export the following properties:
463
463
464
464
- `scheme`: the URL scheme (`http`), always set.
465
- - `host`: the URL host (`example.com`), always set .
465
+ - `host`: the URL host (`example.com`).
466
466
- `username`: optional username if included (`samuel`).
467
467
- `password`: optional password if included (`pass`).
468
468
- `port`: optional port (`8000`).
@@ -471,13 +471,6 @@ class AnyUrl(_BaseUrl):
471
471
- `fragment`: optional fragment (`fragment=is;this=bit`).
472
472
"""
473
473
474
- _constraints = UrlConstraints (host_required = True )
475
-
476
- @property
477
- def host (self ) -> str :
478
- """The required URL host."""
479
- return self ._url .host # pyright: ignore[reportReturnType]
480
-
481
474
482
475
# Note: all single host urls inherit from `AnyUrl` to preserve compatibility with pre-v2.10 code
483
476
# Where urls were annotated variants of `AnyUrl`, which was an alias to `pydantic_core.Url`
@@ -487,17 +480,17 @@ class AnyHttpUrl(AnyUrl):
487
480
"""A type that will accept any http or https URL.
488
481
489
482
* TLD not required
490
- * Host required
483
+ * Host not required
491
484
"""
492
485
493
- _constraints = UrlConstraints (host_required = True , allowed_schemes = ['http' , 'https' ])
486
+ _constraints = UrlConstraints (allowed_schemes = ['http' , 'https' ])
494
487
495
488
496
489
class HttpUrl (AnyUrl ):
497
490
"""A type that will accept any http or https URL.
498
491
499
492
* TLD not required
500
- * Host required
493
+ * Host not required
501
494
* Max length 2083
502
495
503
496
```python
@@ -571,33 +564,28 @@ class MyModel(BaseModel):
571
564
(or at least big) company.
572
565
"""
573
566
574
- _constraints = UrlConstraints (max_length = 2083 , allowed_schemes = ['http' , 'https' ], host_required = True )
567
+ _constraints = UrlConstraints (max_length = 2083 , allowed_schemes = ['http' , 'https' ])
575
568
576
569
577
570
class AnyWebsocketUrl (AnyUrl ):
578
571
"""A type that will accept any ws or wss URL.
579
572
580
573
* TLD not required
581
- * Host required
574
+ * Host not required
582
575
"""
583
576
584
- _constraints = UrlConstraints (allowed_schemes = ['ws' , 'wss' ], host_required = True )
577
+ _constraints = UrlConstraints (allowed_schemes = ['ws' , 'wss' ])
585
578
586
579
587
580
class WebsocketUrl (AnyUrl ):
588
581
"""A type that will accept any ws or wss URL.
589
582
590
583
* TLD not required
591
- * Host required
584
+ * Host not required
592
585
* Max length 2083
593
586
"""
594
587
595
- _constraints = UrlConstraints (max_length = 2083 , allowed_schemes = ['ws' , 'wss' ], host_required = True )
596
-
597
- @property
598
- def host (self ) -> str :
599
- """The required URL host."""
600
- return self ._url .host # type: ignore
588
+ _constraints = UrlConstraints (max_length = 2083 , allowed_schemes = ['ws' , 'wss' ])
601
589
602
590
603
591
class FileUrl (AnyUrl ):
@@ -608,25 +596,15 @@ class FileUrl(AnyUrl):
608
596
609
597
_constraints = UrlConstraints (allowed_schemes = ['file' ])
610
598
611
- @property
612
- def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
613
- """The host part of the URL, or `None`."""
614
- return self ._url .host
615
-
616
599
617
600
class FtpUrl (AnyUrl ):
618
601
"""A type that will accept ftp URL.
619
602
620
603
* TLD not required
621
- * Host required
604
+ * Host not required
622
605
"""
623
606
624
- _constraints = UrlConstraints (allowed_schemes = ['ftp' ], host_required = True )
625
-
626
- @property
627
- def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
628
- """The host part of the URL, or `None`."""
629
- return self ._url .host
607
+ _constraints = UrlConstraints (allowed_schemes = ['ftp' ])
630
608
631
609
632
610
class PostgresDsn (_BaseMultiHostUrl ):
@@ -727,6 +705,11 @@ class CockroachDsn(AnyUrl):
727
705
],
728
706
)
729
707
708
+ @property
709
+ def host (self ) -> str :
710
+ """The required URL host."""
711
+ return self ._url .host # pyright: ignore[reportReturnType]
712
+
730
713
731
714
class AmqpDsn (AnyUrl ):
732
715
"""A type that will accept any AMQP DSN.
@@ -738,11 +721,6 @@ class AmqpDsn(AnyUrl):
738
721
739
722
_constraints = UrlConstraints (allowed_schemes = ['amqp' , 'amqps' ])
740
723
741
- @property
742
- def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
743
- """The host part of the URL, or `None`."""
744
- return self ._url .host
745
-
746
724
747
725
class RedisDsn (AnyUrl ):
748
726
"""A type that will accept any Redis DSN.
@@ -760,6 +738,11 @@ class RedisDsn(AnyUrl):
760
738
host_required = True ,
761
739
)
762
740
741
+ @property
742
+ def host (self ) -> str :
743
+ """The required URL host."""
744
+ return self ._url .host # pyright: ignore[reportReturnType]
745
+
763
746
764
747
class MongoDsn (_BaseMultiHostUrl ):
765
748
"""A type that will accept any MongoDB DSN.
@@ -778,12 +761,10 @@ class KafkaDsn(AnyUrl):
778
761
779
762
* User info required
780
763
* TLD not required
781
- * Host required
764
+ * Host not required
782
765
"""
783
766
784
- _constraints = UrlConstraints (
785
- allowed_schemes = ['kafka' ], default_host = 'localhost' , default_port = 9092 , host_required = True
786
- )
767
+ _constraints = UrlConstraints (allowed_schemes = ['kafka' ], default_host = 'localhost' , default_port = 9092 )
787
768
788
769
789
770
class NatsDsn (_BaseMultiHostUrl ):
@@ -805,7 +786,7 @@ class MySQLDsn(AnyUrl):
805
786
806
787
* User info required
807
788
* TLD not required
808
- * Host required
789
+ * Host not required
809
790
"""
810
791
811
792
_constraints = UrlConstraints (
@@ -829,13 +810,12 @@ class MariaDBDsn(AnyUrl):
829
810
830
811
* User info required
831
812
* TLD not required
832
- * Host required
813
+ * Host not required
833
814
"""
834
815
835
10000
code>
816
_constraints = UrlConstraints (
836
817
allowed_schemes = ['mariadb' , 'mariadb+mariadbconnector' , 'mariadb+pymysql' ],
837
818
default_port = 3306 ,
838
- host_required = True ,
839
819
)
840
820
841
821
@@ -844,14 +824,13 @@ class ClickHouseDsn(AnyUrl):
844
824
845
825
* User info required
846
826
* TLD not required
847
- * Host required
827
+ * Host not required
848
828
"""
849
829
850
830
_constraints = UrlConstraints (
851
831
allowed_schemes = ['clickhouse+native' , 'clickhouse+asynch' ],
852
832
default_host = 'localhost' ,
853
833
default_port = 9000 ,
854
- host_required = True ,
855
834
)
856
835
857
836
@@ -868,6 +847,11 @@ class SnowflakeDsn(AnyUrl):
868
847
host_required = True ,
869
848
)
870
849
850
+ @property
851
+ def host (self ) -> str :
852
+ """The required URL host."""
853
+ return self ._url .host # pyright: ignore[reportReturnType]
854
+
871
855
872
856
def import_email_validator () -> None :
873
857
global email_validator
0 commit comments