@@ -475,10 +475,14 @@ class AnyUrl(_BaseUrl):
475
475
@property
476
476
def host (self ) -> str :
477
477
"""The required URL host."""
478
- return self ._url .host # type: ignore
478
+ return self ._url .host # pyright: ignore[reportReturnType]
479
+
479
480
481
+ # Note: all single host urls inherit from `AnyUrl` to preserve compatibility with pre-v2.10 code
482
+ # Where urls were annotated variants of `AnyUrl`, which was an alias to `pydantic_core.Url`
480
483
481
- class AnyHttpUrl (_BaseUrl ):
484
+
485
+ class AnyHttpUrl (AnyUrl ):
482
486
"""A type that will accept any http or https URL.
483
487
484
488
* TLD not required
@@ -487,13 +491,8 @@ class AnyHttpUrl(_BaseUrl):
487
491
488
492
_constraints = UrlConstraints (host_required = True , allowed_schemes = ['http' , 'https' ])
489
493
490
- @property
491
- def host (self ) -> str :
492
- """The required URL host."""
493
- return self ._url .host # type: ignore
494
-
495
494
496
- class HttpUrl (_BaseUrl ):
495
+ class HttpUrl (AnyUrl ):
497
496
"""A type that will accept any http or https URL.
498
497
499
498
* TLD not required
@@ -573,13 +572,8 @@ class MyModel(BaseModel):
573
572
574
573
_constraints = UrlConstraints (max_length = 2083 , allowed_schemes = ['http' , 'https' ], host_required = True )
575
574
576
- @property
577
- def host (self ) -> str :
578
- """The required URL host."""
579
- return self ._url .host # type: ignore
580
575
581
-
582
- class AnyWebsocketUrl (_BaseUrl ):
576
+ class AnyWebsocketUrl (AnyUrl ):
583
577
"""A type that will accept any ws or wss URL.
584
578
585
579
* TLD not required
@@ -588,13 +582,8 @@ class AnyWebsocketUrl(_BaseUrl):
588
582
589
583
_constraints = UrlConstraints (allowed_schemes = ['ws' , 'wss' ], host_required = True )
590
584
591
- @property
592
- def host (self ) -> str :
593
- """The required URL host."""
594
- return self ._url .host # type: ignore
595
585
596
-
597
- class WebsocketUrl (_BaseUrl ):
586
+ class WebsocketUrl (AnyUrl ):
598
587
"""A type that will accept any ws or wss URL.
599
588
600
589
* TLD not required
@@ -610,16 +599,21 @@ def host(self) -> str:
610
599
return self ._url .host # type: ignore
611
600
612
601
613
- class FileUrl (_BaseUrl ):
602
+ class FileUrl (AnyUrl ):
614
603
"""A type that will accept any file URL.
615
604
616
605
* Host not required
617
606
"""
618
607
619
608
_constraints = UrlConstraints (allowed_schemes = ['file' ])
620
609
610
+ @property
611
+ def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
612
+ """The host part of the URL, or `None`."""
613
+ return self ._url .host
614
+
621
615
622
- class FtpUrl (_BaseUrl ):
616
+ class FtpUrl (AnyUrl ):
623
617
"""A type that will accept ftp URL.
624
618
625
619
* TLD not required
@@ -628,6 +622,11 @@ class FtpUrl(_BaseUrl):
628
622
629
623
_constraints = UrlConstraints (allowed_schemes = ['ftp' ], host_required = True )
630
624
625
+ @property
626
+ def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
627
+ """The host part of the URL, or `None`."""
628
+ return self ._url .host
629
+
631
630
632
631
class PostgresDsn (_BaseMultiHostUrl ):
633
632
"""A type that will accept any Postgres DSN.
@@ -707,10 +706,10 @@ def check_db_name(cls, v):
707
706
@property
708
707
def host (self ) -> str :
709
708
"""The required URL host."""
710
- return self ._url .host # type : ignore
709
+ return self ._url .host # pyright : ignore[reportAttributeAccessIssue]
711
710
712
711
713
- class CockroachDsn (_BaseUrl ):
712
+ class CockroachDsn (AnyUrl ):
714
713
"""A type that will accept any Cockroach DSN.
715
714
716
715
* User info required
@@ -727,13 +726,8 @@ class CockroachDsn(_BaseUrl):
727
726
],
728
727
)
729
728
730
- @property
731
- def host (self ) -> str :
732
- """The required URL host."""
733
- return self ._url .host # type: ignore
734
-
735
729
736
- class AmqpDsn (_BaseUrl ):
730
+ class AmqpDsn (AnyUrl ):
737
731
"""A type that will accept any AMQP DSN.
738
732
739
733
* User info required
@@ -743,8 +737,13 @@ class AmqpDsn(_BaseUrl):
743
737
744
738
_constraints = UrlConstraints (allowed_schemes = ['amqp' , 'amqps' ])
745
739
740
+ @property
741
+ def host (self ) -> str | None : # pyright: ignore[reportIncompatibleMethodOverride]
742
+ """The host part of the URL, or `None`."""
743
+ return self ._url .host
744
+
746
745
747
- class RedisDsn (_BaseUrl ):
746
+ class RedisDsn (AnyUrl ):
748
747
"""A type that will accept any Redis DSN.
749
748
750
749
* User info required
@@ -760,11 +759,6 @@ class RedisDsn(_BaseUrl):
760
759
host_required = True ,
761
760
)
762
761
763
- @property
764
- def host (self ) -> str :
765
- """The required URL host."""
766
- return self ._url .host # type: ignore
767
-
768
762
769
763
class MongoDsn (_BaseMultiHostUrl ):
770
764
"""A type that will accept any MongoDB DSN.
@@ -778,7 +772,7 @@ class MongoDsn(_BaseMultiHostUrl):
778
772
_constraints = UrlConstraints (allowed_schemes = ['mongodb' , 'mongodb+srv' ], default_port = 27017 )
779
773
780
774
781
- class KafkaDsn (_BaseUrl ):
775
+ class KafkaDsn (AnyUrl ):
782
776
"""A type that will accept any Kafka DSN.
783
777
784
778
* User info required
@@ -805,7 +799,7 @@ class NatsDsn(_BaseMultiHostUrl):
805
799
)
806
800
807
801
808
- class MySQLDsn (_BaseUrl ):
802
+ class MySQLDsn (AnyUrl ):
809
803
"""A type that will accept any MySQL DSN.
810
804
811
805
* User info required
@@ -828,13 +822,8 @@ class MySQLDsn(_BaseUrl):
828
822
host_required = True ,
829
823
)
830
824
831
- @property
832
- def host (self ) -> str :
833
- """The required URL host."""
834
- return self ._url .host # type: ignore
835
-
836
825
837
- class MariaDBDsn (_BaseUrl ):
826
+ class MariaDBDsn (AnyUrl ):
838
827
"""A type that will accept any MariaDB DSN.
839
828
840
829
* User info required
@@ -848,13 +837,8 @@ class MariaDBDsn(_BaseUrl):
848
837
host_required = True ,
849
838
)
850
839
851
- @property
852
- def host (self ) -> str :
853
- """The required URL host."""
854
- return self ._url .host # type: ignore
855
-
856
840
857
- class ClickHouseDsn (_BaseUrl ):
841
+ class ClickHouseDsn (AnyUrl ):
858
842
"""A type that will accept any ClickHouse DSN.
859
843
860
844
* User info required
@@ -869,13 +853,8 @@ class ClickHouseDsn(_BaseUrl):
869
853
host_required = True ,
870
854
)
871
855
872
- @property
873
- def host (self ) -> str :
874
- """The required URL host."""
875
- return self ._url .host # type: ignore
876
-
877
856
878
- class SnowflakeDsn (_BaseUrl ):
857
+ class SnowflakeDsn (AnyUrl ):
879
858
"""A type that will accept any Snowflake DSN.
880
859
881
860
* User info required
@@ -888,11 +867,6 @@ class SnowflakeDsn(_BaseUrl):
888
867
host_required = True ,
889
868
)
890
869
891
- @property
892
- def host (self ) -> str :
893
- """The required URL host."""
894
- return self ._url .host # type: ignore
895
-
896
870
897
871
def import_email_validator () -> None :
898
872
global email_validator
0 commit comments