287 Commits
Author SHA1 Message Date
OOTS 4b0e334843 gh-157899: Add support for fds pointing to symlinks in os.readlink(). (GH-157915) 2026-10-13 16:26:22 +00:00
Alex Malyshev 560738126e gh-156491: Avoid KeyErrors in os._Environ.get() and __contains__() (GH-156492)
Implement get() and __contains__() on os._Environ directly, which cuts out the
cost of raising and catching a KeyError when the keys do not exist.
2026-10-08 14:32:33 -07:00
Russell DavisandSerhiy Storchaka fcfa919d9c gh-84687: Add filename to the error raised by os.exec* (GH-19915)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-08-11 16:08:15 +03:00
Serhiy Storchaka a5cb7c34dd gh-150285: Fix too long docstrings in the os module (GH-150296) 2026-05-24 15:04:01 +03:00
9770e32ce0 gh-86533: Restore os.makedirs() ability to apply *mode* recursively (GH-150011)
bpo-42367: Restore os.makedirs() and pathlib.mkdir() ability to apply *mode* recursively via a new parent_mode= keyword argument.

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-05-18 23:00:27 +00:00
b85e10fd12 gh-120057: add os.reload_environ to __all__ (#140763)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-10-29 21:21:26 +00:00
fe9ac7fc8c gh-83714: Implement os.statx() function (#139178)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-15 13:44:08 +00:00
Victor Stinner 35e9d41a9c gh-139482: Add posix._clearenv() function (#139965) 2025-10-11 22:58:43 +02:00
Barney Gale b19ad11027 GH-119169: Slightly speed up os.walk(topdown=True) (GH-121431)
GH-119186: Slightly speed up `os.walk(topdown=True)`

When `os.walk()` traverses into subdirectories in top-down mode, call
`os.path.join()` once to add a trailing slash, and use string concatenation
thereafter to generate child paths.
2025-09-03 13:57:01 +02:00
sobolevn 980a56843b gh-136087: Remove \r from documented os.linesep values (#136088) 2025-06-30 10:12:05 +03:00
Victor Stinner e004cf8fd5 gh-134993: Add os.lstat() to os.supports_dir_fd (#135188) 2025-06-06 14:11:49 +02:00
TotosukiandBénédikt Tran a5949986d6 gh-127541: Update os.walk example (GH-127765)
Update os.walk example to be more modern, skip `__pycache__` dirs rather than `CVS` dirs.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-28 23:25:13 -07:00
4a0d574273 gh-120057: Add os.reload_environ() function (#126268)
Replace the os.environ.refresh() method with a new
os.reload_environ() function.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-11-05 08:43:34 +01:00
Barney Gale db00fee3a2 GH-119169: Simplify os.walk() exception handling (#121435)
Handle errors from `os.scandir()` and `ScandirIterator` similarly, which
lets us loop over directory entries with `for`.
2024-07-08 17:41:01 +01:00
Victor Stinner 7aff2de62b gh-120057: Add os.environ.refresh() method (#120059) 2024-06-10 16:34:17 +00:00
Barney Gale a5fef800d3 GH-89727: Fix FD leak on os.fwalk() generator finalization. (#119766)
Follow-up to 3c890b50. Ensure we `os.close()` open file descriptors when
the `os.fwalk()` generator is finalized.
2024-05-30 03:45:47 +00:00
Barney Gale 3c890b503c GH-89727: Fix os.fwalk() recursion error on deep trees (#119638)
Implement `os.fwalk()` using a list as a stack to avoid emitting recursion
errors on deeply nested trees.
2024-05-30 03:05:36 +00:00
Barney GaleandJelle Zijlstra a150679f90 GH-89727: Partially fix shutil.rmtree() recursion error on deep trees (#119634)
Make `shutil._rmtree_unsafe()` call `os.walk()`, which is implemented
without recursion.

`shutil._rmtree_safe_fd()` is not affected and can still raise a recursion
error.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-29 20:11:30 +00:00
Serhiy Storchaka aa7bcf284f gh-116401: Fix blocking os.fwalk() and shutil.rmtree() on opening a named pipe (GH-116421) 2024-03-13 11:40:28 +02:00
Serhiy Storchaka 1f06baeabd gh-113191: Add support of os.fchmod() on Windows (GH-113192)
Also support a file descriptor in os.chmod().
2023-12-24 10:57:11 +00:00
Serhiy Storchaka 29f7eb4859 gh-59616: Support os.chmod(follow_symlinks=True) and os.lchmod() on Windows (GH-113049) 2023-12-14 13:28:37 +02:00
0362cbf908 gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)
---------

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-10-10 19:00:09 +09:00
Victor Stinner c81521020d gh-109649: Add os.process_cpu_count() function (#109907)
* Refactor os_sched_getaffinity_impl(): move variable definitions to
  their first assignment.
* Fix test_posix.test_sched_getaffinity(): restore the old CPU mask
  when the test completes!
* Doc: Specify that os.cpu_count() counts *logicial* CPUs.
* Doc: Specify that os.sched_getaffinity(0) is related to the calling
  thread.
2023-10-01 00:12:51 +02:00
Alex Waygood 93a970ffbc gh-106046: Improve error message from os.fspath if __fspath__ is set to None (#106082) 2023-06-26 00:06:12 +01:00
Barney Gale bd1b6228d1 GH-104898: Add __slots__ to os.PathLike (GH-104899) 2023-05-25 21:24:20 +01:00
Stanislav Zmiev 73097d91a6 gh-89727: Improve os.walk complexity (#100671) 2023-01-02 13:41:19 -08:00
Jon Burdo 797edb28c3 gh-89727: Fix os.walk RecursionError on deep trees (#99803)
Use a stack to implement os.walk iteratively instead of recursively to
avoid hitting recursion limits on deeply nested trees.
2022-12-19 10:59:01 -08:00
Stanley 0f498f1a95 gh-57179: Add note on symlinks for os.walk (#94799) 2022-10-07 15:51:50 -07:00
Inada Naoki 96f65835f8 gh-87901: Remove the encoding argument from os.popen (GH-92836) 2022-05-19 11:42:43 +09:00
Inada Naoki 2b563f1ad3 gh-87901: Add encoding to os.popen (GH-92374) 2022-05-06 14:48:36 +09:00
辰冢 2a38e1ab65 Fix missing spaces in os.walk example (GH-29918) 2022-02-17 23:10:33 -05:00
Serhiy Storchaka 2b496e7929 bpo-42053: Remove misleading check in os.fwalk() (GH-27669)
os.fwalk() does not support integer as the first argument,
and never supported.
2021-08-08 21:04:02 +03:00
Leonardo FreuaandŁukasz Langa 85fa3b6b7c bpo-44631: Make the repr() of the _Environ class more readable. (#27128)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-07-20 19:15:45 +02:00
Inada Naoki a69256527f bpo-43651: Fix EncodingWarning in os.fdopen() and test_os (GH-25654) 2021-04-29 11:35:36 +09:00
Inada Naoki 35715d1e72 bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25145)
* test_asyncio
* test_bz2
* test_math
* test_cmath
* test_cmd_line
* test_cmd_line_script
* test_compile
* test_contextlib
* test_profile
* ctypes/test/test_find
* test_multiprocessing
* test_configparser
* test_csv
* test_dbm_dumb
* test_decimal
* test_difflib
* os.fdopen() calls io.text_encoding() to emit EncodingWarning for right place.
2021-04-04 09:01:23 +09:00
pxinwr e1e3c2dac3 bpo-31904: Disable os.popen and popen test cases on VxWorks (GH-21687) 2020-12-15 22:20:07 +01:00
Guido van Rossum 48b069a003 bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.

There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
2020-04-07 09:50:06 -07:00
Victor Stinner 65a796e527 bpo-40094: Add os.waitstatus_to_exitcode() (GH-19201)
Add os.waitstatus_to_exitcode() function to convert a wait status to an
exitcode.

Suggest waitstatus_to_exitcode() usage in the documentation when
appropriate.

Use waitstatus_to_exitcode() in:

* multiprocessing, os, subprocess and _bootsubprocess modules;
* test.support.wait_process();
* setup.py: run_command();
* and many tests.
2020-04-01 18:49:29 +02:00
Charles Burkland d648ef10c5 bpo-36144: Update os.environ and os.environb for PEP 584 (#18911) 2020-03-13 09:04:43 -07:00
Serhiy Storchaka f4f445b693 bpo-39567: Add audit for os.walk(), os.fwalk(), Path.glob() and Path.rglob(). (GH-18372) 2020-02-12 12:11:34 +02:00
Victor Stinner b8d1262e8a bpo-39395: putenv() and unsetenv() always available (GH-18135)
The os.putenv() and os.unsetenv() functions are now always available.

On non-Windows platforms, Python now requires setenv() and unsetenv()
functions to build.

Remove putenv_dict from posixmodule.c: it's not longer needed.
2020-01-24 14:05:48 +01:00
Bar Harel eae87e3e4e bpo-38878: Fix os.PathLike __subclasshook__ (GH-17336)
Quick subclasshook fix using the same method is being used in collections.abc (up to a certain degree).
2019-12-22 09:57:27 +00:00
Batuhan Taşkaya 526606baf7 bpo-38994: Implement __class_getitem__ for PathLike (GH-17498)
https://bugs.python.org/issue38994
2019-12-08 12:31:15 -08:00
Bernt Røskar Brenna 734f1202a5 closes bpo-25461: Update os.walk() docstring to match the online docs. (GH-11836) 2019-09-10 13:43:58 +01:00
Hasan Ramezani fb6807b043 Fix punctuation in os.execvpe docstring. (GH-15051) 2019-09-09 08:58:21 -07:00
Steve Dower 2438cdf0e9 bpo-36085: Enable better DLL resolution on Windows (GH-12302) 2019-03-29 16:37:16 -07:00
Recursing 3ce3dea606 Use generator instead of list in code examples (GH-11203)
There is no need to create a list for `sum`
Also, becomes consistent with the first example in Doc/library/os.rst
2018-12-22 19:48:14 -08:00
Benjamin Peterson 52dee687af Assume the raw environ is always declared. (GH-8707)
posixmodule.c always declares environ, so don't bother catching a NameError in os.py.
2018-08-07 21:51:12 -07:00
Mike 53f7a7c281 bpo-32297: Few misspellings found in Python source code comments. (#4803)
* Fix multiple typos in code comments

* Add spacing in comments (test_logging.py, test_math.py)

* Fix spaces at the beginning of comments in test_logging.py
2017-12-14 13:04:53 +02:00
Serhiy Storchaka 81108375d9 bpo-30152: Reduce the number of imports for argparse. (#1269) 2017-09-26 00:55:55 +03:00