[LyX/2.3.x] cat.py: fix Python deprecation warning

Scott Kostyshak skostysh at lyx.org
Fri Aug 25 15:07:58 UTC 2023


commit dee5eec15f6e9c36e7fe858c0bb9d44da051418f
Author: Scott Kostyshak <skostysh at lyx.org>
Date:   Thu Mar 19 18:22:16 2020 -0400

    cat.py: fix Python deprecation warning
    
    This commit fixes the following warning:
    
      DeprecationWarning: 'U' mode is deprecated
    
    Removing 'U' has no effect with Python 3 [1]:
    
      There is an additional mode character permitted, 'U', which no
      longer has any effect, and is considered deprecated. It previously
      enabled universal newlines in text mode, which became the default
      behaviour in Python 3.0.
    
    [1] https://docs.python.org/3/library/functions.html?highlight=open#open
    
    (cherry picked from commit 9715d3504c6a74f9a498e2d9232956255110225d)
---
 development/cmake/po/cat.py |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/development/cmake/po/cat.py b/development/cmake/po/cat.py
index 7a1ee26..fd676cc 100644
--- a/development/cmake/po/cat.py
+++ b/development/cmake/po/cat.py
@@ -29,9 +29,17 @@ if outfile:
 	out = open(outfile, "wb")
 
 for f in args:
-	# accept both windows and unix line endings, since it can happen that we
-	# are on unix, but the file has been written on windows or vice versa.
-	fil = open(f, "rU")
+	if sys.version_info[0] < 3:
+		# accept both windows and unix line endings, since it can
+		# happen that we are on unix, but the file has been written on
+		# windows or vice versa.
+		mode = "rU"
+	else:
+		# The default behavior of Python 3 is to enable universal
+		# newlines in text mode. Adding "U" gives a deprecation
+		# warning.
+		mode = "r"
+	fil = open(f, mode)
 	for l in fil:
 		# this does always write unix line endings since the file has
 		# been opened in binary mode. This is needed since both gettext


More information about the lyx-cvs mailing list