Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1f401a

Browse files
author
Erlend Egeberg Aasland
authored
bpo-42264: Deprecate sqlite3.OptimizedUnicode (GH-23163)
1 parent296a796 commita1f401a

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

‎Doc/whatsnew/3.10.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ Deprecated
360360
as appropriate to help identify code which needs updating during
361361
this transition.
362362

363+
* ``sqlite3.OptimizedUnicode`` has been undocumented and obsolete since Python
364+
3.3, when it was made an alias to:class:`str`. It is now deprecated,
365+
scheduled for removal in Python 3.12.
366+
(Contributed by Erlend E. Aasland in:issue:`42264`.)
367+
363368

364369
Removed
365370
=======

‎Lib/sqlite3/__init__.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@
2121
# 3. This notice may not be removed or altered from any source distribution.
2222

2323
fromsqlite3.dbapi2import*
24+
25+
26+
# bpo-42264: OptimizedUnicode was deprecated in Python 3.10. It's scheduled
27+
# for removal in Python 3.12.
28+
def__getattr__(name):
29+
ifname=="OptimizedUnicode":
30+
importwarnings
31+
msg= ("""
32+
OptimizedUnicode is deprecated and will be removed in Python 3.12.
33+
Since Python 3.3 it has simply been an alias for 'str'.
34+
""")
35+
warnings.warn(msg,DeprecationWarning,stacklevel=2)
36+
returnstr
37+
raiseAttributeError(f"module 'sqlite3' has no attribute '{name}'")

‎Lib/sqlite3/test/factory.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ def CheckCustom(self):
254254
self.assertTrue(row[0].endswith("reich"),"column must contain original data")
255255

256256
defCheckOptimizedUnicode(self):
257-
# In py3k, str objects are always returned when text_factory
258-
# is OptimizedUnicode
259-
self.con.text_factory=sqlite.OptimizedUnicode
257+
# OptimizedUnicode is deprecated as of Python 3.10
258+
withself.assertWarns(DeprecationWarning)ascm:
259+
self.con.text_factory=sqlite.OptimizedUnicode
260+
self.assertIn("factory.py",cm.filename)
260261
austria="Österreich"
261262
germany="Deutchland"
262263
a_row=self.con.execute("select ?", (austria,)).fetchone()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``sqlite3.OptimizedUnicode`` has been undocumented and obsolete since Python
2+
3.3, when it was made an alias to:class:`str`. It is now deprecated,
3+
scheduled for removal in Python 3.12.

‎Modules/_sqlite/module.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,6 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
412412
ADD_EXCEPTION(module,"DataError",pysqlite_DataError,pysqlite_DatabaseError);
413413
ADD_EXCEPTION(module,"NotSupportedError",pysqlite_NotSupportedError,pysqlite_DatabaseError);
414414

415-
/* In Python 2.x, setting Connection.text_factory to
416-
OptimizedUnicode caused Unicode objects to be returned for
417-
non-ASCII data and bytestrings to be returned for ASCII data.
418-
Now OptimizedUnicode is an alias for str, so it has no
419-
effect. */
420-
if (PyModule_AddObjectRef(module,"OptimizedUnicode", (PyObject*)&PyUnicode_Type)<0) {
421-
gotoerror;
422-
}
423-
424415
/* Set integer constants */
425416
if (add_integer_constants(module)<0) {
426417
gotoerror;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp