[Python-checkins] bpo-43970: Optimize Path.cwd() in pathlib by not instantiating a class unnecessarily (GH-25699)

ericvsmith webhook-mailer at python.org
Wed Apr 28 19:01:58 EDT 2021


https://github.com/python/cpython/commit/4a85718212fd032c922ca7d630b2602dd4b29a35
commit: 4a85718212fd032c922ca7d630b2602dd4b29a35
branch: master
author: kfollstad <kfollstad at gmail.com>
committer: ericvsmith <ericvsmith at users.noreply.github.com>
date: 2021-04-28T19:01:51-04:00
summary:

bpo-43970: Optimize Path.cwd() in pathlib by not instantiating a class unnecessarily (GH-25699)

files:
M Lib/pathlib.py

diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 073fce82ad570..cf40370c049a3 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -978,7 +978,7 @@ def cwd(cls):
         """Return a new path pointing to the current working directory
         (as returned by os.getcwd()).
         """
-        return cls(cls()._accessor.getcwd())
+        return cls(cls._accessor.getcwd())
 
     @classmethod
     def home(cls):



More information about the Python-checkins mailing list