mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
GH-110109: pathlib ABCs: drop use of io.text_encoding()
(#113417)
Do not use the locale-specific default encoding in `PathBase.read_text()` and `write_text()`. Locale settings shouldn't influence the operation of these base classes, which are intended mostly for implementing rich paths on *nonlocal* filesystems.
This commit is contained in:
parent
712afab5ac
commit
f8b6e171ad
2 changed files with 18 additions and 3 deletions
|
@ -1,5 +1,4 @@
|
|||
import functools
|
||||
import io
|
||||
import ntpath
|
||||
import posixpath
|
||||
import sys
|
||||
|
@ -755,7 +754,6 @@ class PathBase(PurePathBase):
|
|||
"""
|
||||
Open the file in text mode, read it, and close the file.
|
||||
"""
|
||||
encoding = io.text_encoding(encoding)
|
||||
with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
|
||||
return f.read()
|
||||
|
||||
|
@ -775,7 +773,6 @@ class PathBase(PurePathBase):
|
|||
if not isinstance(data, str):
|
||||
raise TypeError('data must be str, not %s' %
|
||||
data.__class__.__name__)
|
||||
encoding = io.text_encoding(encoding)
|
||||
with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
|
||||
return f.write(data)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue