@@ -311,18 +311,20 @@ def _open_code_with_warning(path): |
|
|
311 |
311 |
open_code = _open_code_with_warning |
312 |
312 |
|
313 |
313 |
|
314 |
|
-class DocDescriptor: |
315 |
|
-"""Helper for builtins.open.__doc__ |
316 |
|
- """ |
317 |
|
-def __get__(self, obj, typ=None): |
318 |
|
-return ( |
319 |
|
-"open(file, mode='r', buffering=-1, encoding=None, " |
320 |
|
-"errors=None, newline=None, closefd=True)\n\n" + |
321 |
|
-open.__doc__) |
322 |
|
- |
323 |
|
- |
324 |
|
-# bpo-43680: Alias to open() kept for backward compatibility |
325 |
|
-OpenWrapper = open |
|
314 |
+def __getattr__(name): |
|
315 |
+if name == "OpenWrapper": |
|
316 |
+# bpo-43680: Until Python 3.9, _pyio.open was not a static method and |
|
317 |
+# builtins.open was set to OpenWrapper to not become a bound method |
|
318 |
+# when set to a class variable. _io.open is a built-in function whereas |
|
319 |
+# _pyio.open is a Python function. In Python 3.10, _pyio.open() is now |
|
320 |
+# a static method, and builtins.open() is now io.open(). |
|
321 |
+import warnings |
|
322 |
+warnings.warn('OpenWrapper is deprecated, use open instead', |
|
323 |
+DeprecationWarning, stacklevel=2) |
|
324 |
+global OpenWrapper |
|
325 |
+OpenWrapper = open |
|
326 |
+return OpenWrapper |
|
327 |
+raise AttributeError(name) |
326 |
328 |
|
327 |
329 |
|
328 |
330 |
# In normal operation, both `UnsupportedOperation`s should be bound to the |