2
2
import re
3
3
import sys
4
4
import warnings
5
- from collections .abc import Mapping , Sequence
5
+ from collections .abc import Iterable , Mapping , Sequence
6
6
from contextlib import suppress
7
7
from functools import _CacheInfo , lru_cache
8
8
from ipaddress import ip_address
9
9
from typing import (
10
10
TYPE_CHECKING ,
11
11
Any ,
12
- Iterable ,
13
- List ,
14
12
SupportsInt ,
15
13
Tuple ,
16
14
TypedDict ,
@@ -109,34 +107,34 @@ class _InternalURLCache(TypedDict, total=False):
109
107
explicit_port : Union [int , None ]
110
108
raw_path : str
111
109
path : str
112
- _parsed_query : List [ Tuple [str , str ]]
110
+ _parsed_query : list [ tuple [str , str ]]
113
111
query : "MultiDictProxy[str]"
114
112
raw_query_string : str
115
113
query_string : str
116
114
path_qs : str
117
115
raw_path_qs : str
118
116
raw_fragment : str
119
117
fragment : str
120
- raw_parts : Tuple [str , ...]
121
- parts : Tuple [str , ...]
118
+ raw_parts : tuple [str , ...]
119
+ parts : tuple [str , ...]
122
120
parent : "URL"
123
121
raw_name : str
124
122
name : str
125
123
raw_suffix : str
126
124
suffix : str
127
- raw_suffixes : Tuple [str , ...]
128
- suffixes : Tuple [str , ...]
125
+ raw_suffixes : tuple [str , ...]
126
+ suffixes : tuple [str , ...]
129
127
130
128
131
129
def rewrite_module (obj : _T ) -> _T :
132
130
obj .__module__ = "yarl"
133
131
return obj
134
132
135
133
136
- def _normalize_path_segments (segments : "Sequence[str]" ) -> List [str ]:
134
+ def _normalize_path_segments (segments : "Sequence[str]" ) -> list [str ]:
137
135
"""Drop '.' and '..' from a sequence of str segments"""
138
136
139
- resolved_path : List [str ] = []
137
+ resolved_path : list [str ] = []
140
138
141
139
for seg in segments :
142
140
if seg == ".." :
@@ -504,7 +502,7 @@ def __bool__(self) -> bool:
504
502
val = self ._val
505
503
return bool (val .netloc or val .path or val .query or val .fragment )
506
504
507
- def __getstate__ (self ) -> Tuple [SplitResult ]:
505
+ def __getstate__ (self ) -> tuple [SplitResult ]:
508
506
return (self ._val ,)
509
507
510
508
def __setstate__ (self , state ):
@@ -786,7 +784,7 @@ def path_safe(self) -> str:
786
784
return self ._PATH_SAFE_UNQUOTER (self .raw_path )
787
785
788
786
@cached_property
789
- def _parsed_query (self ) -> List [ Tuple [str , str ]]:
787
+ def _parsed_query (self ) -> list [ tuple [str , str ]]:
790
788
"""Parse query part of URL."""
791
789
return parse_qsl (self ._val .query , keep_blank_values = True )
792
790
@@ -851,7 +849,7 @@ def fragment(self) -> str:
851
849
return self ._UNQUOTER (self ._val .fragment )
852
850
853
851
@cached_property
854
- def raw_parts (self ) -> Tuple [str , ...]:
852
+ def raw_parts (self ) -> tuple [str , ...]:
855
853
"""A tuple containing encoded *path* parts.
856
854
857
855
('/',) for absolute URLs if *path* is missing.
@@ -865,7 +863,7 @@ def raw_parts(self) -> Tuple[str, ...]:
865
863
return tuple (path .split ("/" ))
866
864
867
865
@cached_property
868
- def parts (self ) -> Tuple [str , ...]:
866
+ def parts (self ) -> tuple [str , ...]:
869
867
"""A tuple containing decoded *path* parts.
870
868
871
869
('/',) for absolute URLs if *path* is missing.
@@ -920,15 +918,15 @@ def suffix(self) -> str:
920
918
return self ._UNQUOTER (self .raw_suffix )
921
919
922
920
@cached_property
923
- def raw_suffixes (self ) -> Tuple [str , ...]:
921
+ def raw_suffixes (self ) -> tuple [str , ...]:
924
922
name = self .raw_name
925
923
if name .endswith ("." ):
926
924
return ()
927
925
name = name .lstrip ("." )
928
926
return tuple ("." + suffix for suffix in name .split ("." )[1 :])
929
927
930
928
@cached_property
931
- def suffixes (self ) -> Tuple [str , ...]:
929
+ def suffixes (self ) -> tuple [str , ...]:
932
930
return tuple (self ._UNQUOTER (suffix ) for suffix in self .raw_suffixes )
933
931
934
932
@staticmethod
@@ -947,7 +945,7 @@ def _make_child(self, paths: "Sequence[str]", encoded: bool = False) -> "URL":
947
945
add paths to self._val.path, accounting for absolute vs relative paths,
948
946
keep existing, but do not create new, empty segments
949
947
"""
950
- parsed : List [str ] = []
948
+ parsed : list [str ] = []
951
949
needs_normalize : bool = False
952
950
for idx , path in enumerate (reversed (paths )):
953
951
# empty segment of last is not removed
@@ -995,7 +993,7 @@ def _normalize_path(cls, path: str) -> str:
995
993
@lru_cache # match the same size as urlsplit
996
994
def _parse_host (
997
995
cls , host : str
998
- ) -> Tuple [bool , str , Union [bool , None ], str , str , str ]:
996
+ ) -> tuple [bool , str , Union [bool , None ], str , str , str ]:
999
997
"""Parse host into parts
1000
998
1001
999
Returns a tuple of:
@@ -1111,7 +1109,7 @@ def _make_netloc(
1111
1109
def _split_netloc (
1112
1110
cls ,
1113
1111
netloc : str ,
1114
- ) -> Tuple [Union [str , None ], Union [str , None ], Union [str , None ], Union [int , None ]]:
1112
+ ) -> tuple [Union [str , None ], Union [str , None ], Union [str , None ], Union [int , None ]]:
1115
1113
"""Split netloc into username, password, host and port."""
1116
1114
if "@" not in netloc :
1117
1115
username : Union [str , None ] = None
@@ -1253,7 +1251,7 @@ def with_path(self, path: str, *, encoded: bool = False) -> "URL":
1253
1251
1254
1252
def _get_str_query_from_sequence_iterable (
1255
1253
self ,
1256
- items : Iterable [Tuple [Union [str , istr ], QueryVariable ]],
1254
+ items : Iterable [tuple [Union [str , istr ], QueryVariable ]],
1257
1255
) -> str :
1258
1256
"""Return a query string from a sequence of (key, value) pairs.
1259
1257
@@ -1299,7 +1297,7 @@ def _query_var(v: QueryVariable) -> str:
1299
1297
)
1300
1298
1301
1299
def _get_str_query_from_iterable (
1302
- self , items : Iterable [Tuple [Union [str , istr ], str ]]
1300
+ self , items : Iterable [tuple [Union [str , istr ], str ]]
1303
1301
) -> str :
1304
1302
"""Return a query string from an iterable.
1305
1303
@@ -1622,7 +1620,7 @@ def _idna_encode(host: str) -> str:
1622
1620
1623
1621
1624
1622
@lru_cache (_MAXCACHE )
1625
- def _ip_compressed_version (raw_ip : str ) -> Tuple [str , int ]:
1623
+ def _ip_compressed_version (raw_ip : str ) -> tuple [str , int ]:
1626
1624
"""Return compressed version of IP address and its version."""
1627
1625
ip = ip_address (raw_ip )
1628
1626
return ip .compressed , ip .version
0 commit comments