mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	gh-117584: Raise TypeError for non-paths in posixpath.relpath() (GH-117585)
This commit is contained in:
		
							parent
							
								
									62aeb0ee69
								
							
						
					
					
						commit
						733e56ef96
					
				
					 3 changed files with 3 additions and 1 deletions
				
			
		| 
						 | 
					@ -502,10 +502,10 @@ def realpath(filename, *, strict=False):
 | 
				
			||||||
def relpath(path, start=None):
 | 
					def relpath(path, start=None):
 | 
				
			||||||
    """Return a relative version of a path"""
 | 
					    """Return a relative version of a path"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    path = os.fspath(path)
 | 
				
			||||||
    if not path:
 | 
					    if not path:
 | 
				
			||||||
        raise ValueError("no path specified")
 | 
					        raise ValueError("no path specified")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    path = os.fspath(path)
 | 
					 | 
				
			||||||
    if isinstance(path, bytes):
 | 
					    if isinstance(path, bytes):
 | 
				
			||||||
        curdir = b'.'
 | 
					        curdir = b'.'
 | 
				
			||||||
        sep = b'/'
 | 
					        sep = b'/'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -650,6 +650,7 @@ def test_relpath(self):
 | 
				
			||||||
        (real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
 | 
					        (real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            curdir = os.path.split(os.getcwd())[-1]
 | 
					            curdir = os.path.split(os.getcwd())[-1]
 | 
				
			||||||
 | 
					            self.assertRaises(TypeError, posixpath.relpath, None)
 | 
				
			||||||
            self.assertRaises(ValueError, posixpath.relpath, "")
 | 
					            self.assertRaises(ValueError, posixpath.relpath, "")
 | 
				
			||||||
            self.assertEqual(posixpath.relpath("a"), "a")
 | 
					            self.assertEqual(posixpath.relpath("a"), "a")
 | 
				
			||||||
            self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
 | 
					            self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Raise :exc:`TypeError` for non-paths in :func:`posixpath.relpath()`.
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue