@@ -847,47 +847,11 @@ def test_mixed_types_rejected(self):
847847 with self .assertRaisesRegex (TypeError , "Cannot mix str" ):
848848 urllib .parse .urljoin (b"http://python.org" , "http://python.org" )
849849
850- def test_forbidden_types (self ):
851- with self .assertRaisesRegex (
852- TypeError ,
853- "Expected a string or bytes object: got <class 'list'>" ):
854- urllib .parse .urljoin ('http://www.python.org' , [])
855- with self .assertRaisesRegex (
856- TypeError ,
857- "Expected a string or bytes object: got <class 'list'>" ):
858- urllib .parse .urljoin ([], b'docs' )
859- with self .assertRaisesRegex (
860- TypeError ,
861- "Expected a string or bytes object: got <class 'NoneType'>" ):
862- urllib .parse .urlparse (b'www.python.org' , None )
863- with self .assertRaisesRegex (
864- TypeError ,
865- "Expected a string or bytes object: got <class 'dict'>" ):
866- urllib .parse .urlparse ({}, '' )
867- with self .assertRaisesRegex (
868- TypeError ,
869- "Expected a string or bytes object: got <class 'int'>" ):
870- urllib .parse .urlsplit (0 , 'http' )
871- with self .assertRaisesRegex (
872- TypeError ,
873- "Expected a string or bytes object: got <class 'NoneType'>" ):
874- urllib .parse .urlsplit ('http://www.python.org' , None )
875- with self .assertRaisesRegex (
876- TypeError ,
877- "Expected a string or bytes object: got <class 'tuple'>" ):
878- urllib .parse .urldefrag (())
879- with self .assertRaisesRegex (
880- TypeError ,
881- "Expected a string or bytes object: got <class 'NoneType'>" ):
882- urllib .parse .urlunparse ([None , './Python' ,'x-newscheme://foo.com/stuff' ,'x://y' ,'x:/y' ,'x:/' ,'/' ,])
883- with self .assertRaisesRegex (
884- TypeError ,
885- "Expected a string or bytes object: got <class 'int'>" ):
886- urllib .parse .urlunsplit (['http' , 0 , '' , '' , '' ])
887- with self .assertRaisesRegex (
888- TypeError ,
889- "Expected a string or bytes object: got <class 'NoneType'>" ):
890- urllib .parse .parse_qsl (None , encoding = 'latin-1' )
850+ def test_non_string_true_values_rejected (self ):
851+ # True values raise informative TypeErrors
852+ msg = "Expected a string or bytes object: got <class "
853+ with self .assertRaisesRegex (TypeError , msg ):
854+ urllib .parse .urlsplit (1 , b'http' )
891855
892856 def _check_result_type (self , str_type ):
893857 num_args = len (str_type ._fields )
@@ -1378,6 +1342,32 @@ def test_to_bytes_deprecation(self):
13781342 self .assertEqual (str (cm .warning ),
13791343 'urllib.parse.to_bytes() is deprecated as of 3.8' )
13801344
1345+ def test_false_value_deprecation (self ):
1346+ pattern = (
1347+ "Providing false values other than strings or bytes to urllib.parse "
1348+ "is deprecated: got <class "
1349+ )
1350+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1351+ urllib .parse .urljoin ('http://www.python.org' , [])
1352+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1353+ urllib .parse .urljoin ([], b'docs' )
1354+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1355+ urllib .parse .urlparse (b'www.python.org' , None )
1356+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1357+ urllib .parse .urlparse ({}, '' )
1358+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1359+ urllib .parse .urlsplit (0 , b'http' )
1360+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1361+ urllib .parse .urlsplit (b'http://www.python.org' , None )
1362+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1363+ urllib .parse .urldefrag (())
1364+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1365+ urllib .parse .urlunparse ([None , b'www.python.org' , None , None , None , None ])
1366+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1367+ urllib .parse .urlunsplit (['http' , 0 , '' , '' , '' ])
1368+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
1369+ urllib .parse .parse_qsl (None , encoding = 'latin-1' )
1370+
13811371
13821372if __name__ == "__main__" :
13831373 unittest .main ()
0 commit comments