classification
Title: Provide a home() classmethod on Path objects
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, artifex93, martin.panter, neologix, oquanox, pitrou, python-dev, serhiy.storchaka, vstinner
Priority: low Keywords: easy, patch

Created on 2013-11-25 20:04 by pitrou, last changed 2015-01-13 00:48 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
path_home.patch mcsalgado, 2015-01-01 17:20 review
path_home2.patch mcsalgado, 2015-01-01 18:43 review
home.patch oquanox, 2015-01-04 08:58 review
Messages (8)
msg204388 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-25 20:04
Similar to Path.cwd(), perhaps a Path.home() to create a new Path object pointing to the current user's home directory may be useful.
msg204459 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-11-26 07:56
IMO, this functionality is subsumed by http://bugs.python.org/issue19776
(Path.expanduser).
msg225246 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-08-12 23:41
> IMO, this functionality is subsumed by http://bugs.python.org/issue19776

Roughly, yes, but it can also be a useful convenience (expanduser('~') isn't that user-friendly, especially for Windows users).
msg233403 - (view) Author: Mayank Tripathi (oquanox) * Date: 2015-01-04 08:58
Added docs to mcsalgado's patch.
msg233528 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-06 11:46
I agree that Path.home() is more user friendly than Path.expanduser('~').
msg233887 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-12 20:55
+    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)

Why are you using a submethod _test_home()?
msg233888 - (view) Author: Roundup Robot (python-dev) Date: 2015-01-12 21:24
New changeset 4a55b98314cd by Antoine Pitrou in branch 'default':
Issue #19777: Provide a home() classmethod on Path objects.
https://hg.python.org/cpython/rev/4a55b98314cd
msg233898 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-01-13 00:48
I've committed the patch, thank you!
History
Date User Action Args
2015-01-13 00:48:28pitrousetstatus: open -> closed
resolution: fixed
messages: + msg233898

stage: needs patch -> resolved
2015-01-12 21:24:23python-devsetnosy: + python-dev
messages: + msg233888
2015-01-12 20:55:06vstinnersetmessages: + msg233887
2015-01-06 11:46:26vstinnersetnosy: + vstinner
messages: + msg233528
2015-01-04 08:58:33oquanoxsetfiles: + home.patch
nosy: + oquanox
messages: + msg233403

2015-01-01 18:43:19mcsalgadosetfiles: + path_home2.patch
2015-01-01 17:28:23artifex93setnosy: + artifex93
2015-01-01 17:20:10mcsalgadosetfiles: + path_home.patch
keywords: + patch
2015-01-01 12:09:58pitrousetkeywords: + easy
stage: needs patch
2014-11-14 00:32:20martin.pantersetnosy: + martin.panter
2014-08-12 23:41:32pitrousetnosy: + serhiy.storchaka
messages: + msg225246
2013-11-26 07:56:24neologixsetnosy: + neologix
messages: + msg204459
2013-11-26 02:29:49Arfreversetnosy: + Arfrever
2013-11-25 20:04:23pitroucreate