mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #19777: Provide a home() classmethod on Path objects.
Contributed by Victor Salgado and Mayank Tripathi.
This commit is contained in:
		
							parent
							
								
									2b4ec1ce8a
								
							
						
					
					
						commit
						17cba7daf5
					
				
					 5 changed files with 34 additions and 0 deletions
				
			
		| 
						 | 
					@ -628,6 +628,17 @@ call fails (for example because the path doesn't exist):
 | 
				
			||||||
      PosixPath('/home/antoine/pathlib')
 | 
					      PosixPath('/home/antoine/pathlib')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.. classmethod:: Path.home()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Return a new path object representing the user's home directory (as
 | 
				
			||||||
 | 
					   returned by :func:`os.path.expanduser` with ``~`` construct)::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      >>> Path.home()
 | 
				
			||||||
 | 
					      PosixPath('/home/antoine')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   .. versionadded:: 3.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. method:: Path.stat()
 | 
					.. method:: Path.stat()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   Return information about this path (similarly to :func:`os.stat`).
 | 
					   Return information about this path (similarly to :func:`os.stat`).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1008,6 +1008,13 @@ def cwd(cls):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        return cls(os.getcwd())
 | 
					        return cls(os.getcwd())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def home(cls):
 | 
				
			||||||
 | 
					        """Return a new path pointing to the user's home directory (as
 | 
				
			||||||
 | 
					        returned by os.path.expanduser('~')).
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        return cls(cls()._flavour.gethomedir(None))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def samefile(self, other_path):
 | 
					    def samefile(self, other_path):
 | 
				
			||||||
        """Return whether `other_file` is the same or not as this file.
 | 
					        """Return whether `other_file` is the same or not as this file.
 | 
				
			||||||
        (as returned by os.path.samefile(file, other_file)).
 | 
					        (as returned by os.path.samefile(file, other_file)).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1261,6 +1261,17 @@ def test_cwd(self):
 | 
				
			||||||
        p = self.cls.cwd()
 | 
					        p = self.cls.cwd()
 | 
				
			||||||
        self._test_cwd(p)
 | 
					        self._test_cwd(p)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _test_home(self, p):
 | 
				
			||||||
 | 
					        q = self.cls(os.path.expanduser('~'))
 | 
				
			||||||
 | 
					        self.assertEqual(p, q)
 | 
				
			||||||
 | 
					        self.assertEqual(str(p), str(q))
 | 
				
			||||||
 | 
					        self.assertIs(type(p), type(q))
 | 
				
			||||||
 | 
					        self.assertTrue(p.is_absolute())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_home(self):
 | 
				
			||||||
 | 
					        p = self.cls.home()
 | 
				
			||||||
 | 
					        self._test_home(p)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_samefile(self):
 | 
					    def test_samefile(self):
 | 
				
			||||||
        fileA_path = os.path.join(BASE, 'fileA')
 | 
					        fileA_path = os.path.join(BASE, 'fileA')
 | 
				
			||||||
        fileB_path = os.path.join(BASE, 'dirB', 'fileB')
 | 
					        fileB_path = os.path.join(BASE, 'dirB', 'fileB')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1201,6 +1201,7 @@ Sébastien Sablé
 | 
				
			||||||
Suman Saha
 | 
					Suman Saha
 | 
				
			||||||
Hajime Saitou
 | 
					Hajime Saitou
 | 
				
			||||||
George Sakkis
 | 
					George Sakkis
 | 
				
			||||||
 | 
					Victor Salgado
 | 
				
			||||||
Rich Salz
 | 
					Rich Salz
 | 
				
			||||||
Kevin Samborn
 | 
					Kevin Samborn
 | 
				
			||||||
Adrian Sampson
 | 
					Adrian Sampson
 | 
				
			||||||
| 
						 | 
					@ -1390,6 +1391,7 @@ David Townshend
 | 
				
			||||||
Nathan Trapuzzano
 | 
					Nathan Trapuzzano
 | 
				
			||||||
Laurence Tratt
 | 
					Laurence Tratt
 | 
				
			||||||
Alberto Trevino
 | 
					Alberto Trevino
 | 
				
			||||||
 | 
					Mayank Tripathi
 | 
				
			||||||
Matthias Troffaes
 | 
					Matthias Troffaes
 | 
				
			||||||
Tom Tromey
 | 
					Tom Tromey
 | 
				
			||||||
John Tromp
 | 
					John Tromp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -203,6 +203,9 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #19777: Provide a home() classmethod on Path objects.  Contributed
 | 
				
			||||||
 | 
					  by Victor Salgado and Mayank Tripathi.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #23206: Make ``json.dumps(..., ensure_ascii=False)`` as fast as the
 | 
					- Issue #23206: Make ``json.dumps(..., ensure_ascii=False)`` as fast as the
 | 
				
			||||||
  default case of ``ensure_ascii=True``.  Patch by Naoki Inada.
 | 
					  default case of ``ensure_ascii=True``.  Patch by Naoki Inada.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue