12
12
Iterable ,
13
13
Iterator ,
14
14
List ,
15
- Optional ,
16
15
Tuple ,
17
16
TypedDict ,
18
17
TypeVar ,
@@ -194,7 +193,7 @@ def __new__(
194
193
val : Union [str , SplitResult , "URL" ] = "" ,
195
194
* ,
196
195
encoded : bool = False ,
197
- strict : Optional [bool ] = None ,
196
+ strict : Union [bool , None ] = None ,
198
197
) -> Self :
199
198
if strict is not None : # pragma: no cover
200
199
warnings .warn ("strict parameter is ignored" )
@@ -211,7 +210,7 @@ def __new__(
211
210
raise TypeError ("Constructor parameter should be str" )
212
211
213
212
if not encoded :
214
- host : Optional [str ]
213
+ host : Union [str , None ]
215
214
if not val [1 ]: # netloc
216
215
netloc = ""
217
216
host = ""
@@ -250,12 +249,12 @@ def build(
250
249
* ,
251
250
scheme : str = "" ,
252
251
authority : str = "" ,
253
- user : Optional [str ] = None ,
254
- password : Optional [str ] = None ,
252
+ user : Union [str , None ] = None ,
253
+ password : Union [str , None ] = None ,
255
254
host : str = "" ,
256
- port : Optional [int ] = None ,
255
+ port : Union [int , None ] = None ,
257
256
path : str = "" ,
258
- query : Optional [_Query ] = None ,
257
+ query : Union [_Query , None ] = None ,
259
258
query_string : str = "" ,
260
259
fragment : str = "" ,
261
260
encoded : bool = False ,
@@ -529,7 +528,7 @@ def authority(self) -> str:
529
528
)
530
529
531
530
@property
532
- def raw_user (self ) -> Optional [str ]:
531
+ def raw_user (self ) -> Union [str , None ]:
533
532
"""Encoded user part of URL.
534
533
535
534
None if user is missing.
@@ -539,7 +538,7 @@ def raw_user(self) -> Optional[str]:
539
538
return self ._val .username or None
540
539
541
540
@cached_property
542
- def user (self ) -> Optional [str ]:
541
+ def user (self ) -> Union [str , None ]:
543
542
"""Decoded user part of URL.
544
543
545
544
None if user is missing.
@@ -551,7 +550,7 @@ def user(self) -> Optional[str]:
551
550
return self ._UNQUOTER (raw_user )
552
551
553
552
@property
554
- def raw_password (self ) -> Optional [str ]:
553
+ def raw_password (self ) -> Union [str , None ]:
555
554
"""Encoded password part of URL.
556
555
557
556
None if password is missing.
@@ -560,7 +559,7 @@ def raw_password(self) -> Optional[str]:
560
559
return self ._val .password
561
560
562
561
@cached_property
563
- def password (self ) -> Optional [str ]:
562
+ def password (self ) -> Union [str , None ]:
564
563
"""Decoded password part of URL.
565
564
566
565
None if password is missing.
@@ -572,7 +571,7 @@ def password(self) -> Optional[str]:
572
571
return self ._UNQUOTER (raw_password )
573
572
574
573
@cached_property
575
- def raw_host (self ) -> Optional [str ]:
574
+ def raw_host (self ) -> Union [str , None ]:
576
575
"""Encoded host part of URL.
577
576
578
577
None for relative URLs.
@@ -583,7 +582,7 @@ def raw_host(self) -> Optional[str]:
583
582
return self ._val .hostname
584
583
585
584
@cached_property
586
- def host (self ) -> Optional [str ]:
585
+ def host (self ) -> Union [str , None ]:
587
586
"""Decoded host part of URL.
588
587
589
588
None for relative URLs.
@@ -600,7 +599,7 @@ def host(self) -> Optional[str]:
600
599
return _idna_decode (raw )
601
600
602
601
@cached_property
603
- def port (self ) -> Optional [int ]:
602
+ def port (self ) -> Union [int , None ]:
604
603
"""Port part of URL, with scheme-based fallback.
605
604
606
605
None for relative URLs or URLs without explicit port and
@@ -610,7 +609,7 @@ def port(self) -> Optional[int]:
610
609
return self .explicit_port or self ._default_port
611
610
612
611
@cached_property
613
- def explicit_port (self ) -> Optional [int ]:
612
+ def explicit_port (self ) -> Union [int , None ]:
614
613
"""Port part of URL, without scheme-based fallback.
615
614
616
615
None for relative URLs or URLs without explicit port.
@@ -893,10 +892,10 @@ def _encode_host(cls, host: str, human: bool = False) -> str:
893
892
@classmethod
894
893
def _make_netloc (
895
894
cls ,
896
- user : Optional [str ],
897
- password : Optional [str ],
898
- host : Optional [str ],
899
- port : Optional [int ],
895
+ user : Union [str , None ],
896
+ password : Union [str , None ],
897
+ host : Union [str , None ],
898
+ port : Union [int , None ],
900
899
encode : bool = False ,
901
900
encode_host : bool = True ,
902
901
requote : bool = False ,
@@ -934,7 +933,7 @@ def with_scheme(self, scheme: str) -> "URL":
934
933
raise ValueError ("scheme replacement is not allowed for relative URLs" )
935
934
return URL (self ._val ._replace (scheme = scheme .lower ()), encoded = True )
936
935
937
- def with_user (self , user : Optional [str ]) -> "URL" :
936
+ def with_user (self , user : Union [str , None ]) -> "URL" :
938
937
"""Return a new URL with user replaced.
939
938
940
939
Autoencode user if needed.
@@ -960,7 +959,7 @@ def with_user(self, user: Optional[str]) -> "URL":
960
959
encoded = True ,
961
960
)
962
961
963
- def with_password (self , password : Optional [str ]) -> "URL" :
962
+ def with_password (self , password : Union [str , None ]) -> "URL" :
964
963
"""Return a new URL with password replaced.
965
964
966
965
Autoencode password if needed.
@@ -1009,7 +1008,7 @@ def with_host(self, host: str) -> "URL":
1009
1008
encoded = True ,
1010
1009
)
1011
1010
1012
- def with_port (self , port : Optional [int ]) -> "URL" :
1011
+ def with_port (self , port : Union [int , None ]) -> "URL" :
1013
1012
"""Return a new URL with port replaced.
1014
1013
1015
1014
Clear port to default if None is passed.
@@ -1077,8 +1076,8 @@ def _query_var(v: _QueryVariable) -> str:
1077
1076
"of type {}" .format (v , cls )
1078
1077
)
1079
1078
1080
- def _get_str_query (self , * args : Any , ** kwargs : Any ) -> Optional [str ]:
1081
- query : Optional [ Union [str , Mapping [str , _QueryVariable ]] ]
1079
+ def _get_str_query (self , * args : Any , ** kwargs : Any ) -> Union [str , None ]:
1080
+ query : Union [str , Mapping [str , _QueryVariable ], None ]
1082
1081
if kwargs :
1083
1082
if len (args ) > 0 :
1084
1083
raise ValueError (
@@ -1163,7 +1162,7 @@ def update_query(self, *args: Any, **kwargs: Any) -> "URL":
1163
1162
self ._val ._replace (query = self ._get_str_query (query ) or "" ), encoded = True
1164
1163
)
1165
1164
1166
- def with_fragment (self , fragment : Optional [str ]) -> "URL" :
1165
+ def with_fragment (self , fragment : Union [str , None ]) -> "URL" :
1167
1166
"""Return a new URL with fragment replaced.
1168
1167
1169
1168
Autoencode fragment if needed.
@@ -1314,7 +1313,7 @@ def human_repr(self) -> str:
1314
1313
return urlunsplit (val )
1315
1314
1316
1315
1317
- def _human_quote (s : Optional [str ], unsafe : str ) -> Optional [str ]:
1316
+ def _human_quote (s : Union [str , None ], unsafe : str ) -> Union [str , None ]:
1318
1317
if not s :
1319
1318
return s
1320
1319
for c in "%" + unsafe :
@@ -1372,9 +1371,9 @@ def cache_info() -> CacheInfo:
1372
1371
@rewrite_module
1373
1372
def cache_configure (
1374
1373
* ,
1375
- idna_encode_size : Optional [int ] = _MAXCACHE ,
1376
- idna_decode_size : Optional [int ] = _MAXCACHE ,
1377
- ip_address_size : Optional [int ] = _MAXCACHE ,
1374
+ idna_encode_size : Union [int , None ] = _MAXCACHE ,
1375
+ idna_decode_size : Union [int , None ] = _MAXCACHE ,
1376
+ ip_address_size : Union [int , None ] = _MAXCACHE ,
1378
1377
) -> None :
1379
1378
"""Configure LRU cache sizes."""
1380
1379
global _idna_decode , _idna_encode , _ip_compressed_version
0 commit comments