Skip to content

Commit b777d82

Browse files
committed
Drop codecs library
Built-in `open()` of python 3 handles file encodings well.
1 parent 2b6041f commit b777d82

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

plugins/cmds.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import codecs
21
import functools
32
import locale
43
import os
@@ -226,9 +225,7 @@ def get_alternate_tags_paths(view, tags_file):
226225

227226
# read and add additional tag file paths from file
228227
if os.path.exists(tags_paths):
229-
search_paths.extend(
230-
codecs.open(tags_paths, encoding="utf-8").read().split("\n")
231-
)
228+
search_paths.extend(open(tags_paths, encoding="utf-8").read().split("\n"))
232229

233230
# read and add additional tag file paths from 'extra_tag_paths' setting
234231
try:
@@ -988,7 +985,7 @@ def __next__(self):
988985
def co_routine(self, view):
989986
tag_file = find_tags_relative_to(view.file_name(), setting("tag_file"))
990987

991-
with codecs.open(tag_file, encoding="utf-8") as tf:
988+
with open(tag_file, encoding="utf-8") as tf:
992989
tags = parse_tag_lines(tf, tag_class=TagElements)
993990

994991
print("Starting Test")

plugins/ctags.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import bisect
6-
import codecs
76
import mmap
87
import os
98
import re
@@ -363,7 +362,7 @@ def resort_ctags(tag_file):
363362
"""
364363
groups = {}
365364

366-
with codecs.open(tag_file, encoding="utf-8", errors="replace") as file_:
365+
with open(tag_file, encoding="utf-8", errors="replace") as file_:
367366
for line in file_:
368367
# meta data not needed in sorted files
369368
if line.startswith("!_TAG"):
@@ -375,7 +374,7 @@ def resort_ctags(tag_file):
375374
if len(split) > FILENAME:
376375
groups.setdefault(split[FILENAME], []).append(line)
377376

378-
with codecs.open(
377+
with open(
379378
tag_file + "_sorted_by_file", "w", encoding="utf-8", errors="replace"
380379
) as file_:
381380
for group in sorted(groups):
@@ -509,7 +508,7 @@ def open(self):
509508
"""
510509
Open file.
511510
"""
512-
self.file_o = codecs.open(self.path, "r+b", encoding="utf-8")
511+
self.file_o = open(self.path, "r", encoding="utf-8")
513512
self.mapped = mmap.mmap(self.file_o.fileno(), 0, access=mmap.ACCESS_READ)
514513

515514
def close(self):

plugins/tests/test_ctags.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Unit tests for 'ctags.py'.
55
"""
66

7-
import codecs
87
import os
98
import tempfile
109
import unittest
@@ -217,7 +216,7 @@ def test_build_ctags__single_file(self):
217216

218217
tag_file = ctags.build_ctags(path=path)
219218

220-
with codecs.open(tag_file, encoding="utf-8") as output:
219+
with open(tag_file, encoding="utf-8") as output:
221220
try:
222221
content = output.readlines()
223222
filename = os.path.basename(path)
@@ -239,7 +238,7 @@ def test_build_ctags__custom_tag_file(self):
239238

240239
tag_file = ctags.build_ctags(path=path, tag_file="my_tag_file")
241240

242-
with codecs.open(tag_file, encoding="utf-8") as output:
241+
with open(tag_file, encoding="utf-8") as output:
243242
try:
244243
content = output.readlines()
245244
filename = os.path.basename(path)
@@ -263,7 +262,7 @@ def test_build_ctags__additional_options(self):
263262
path=path, tag_file="my_tag_file", opts="--language-force=java"
264263
)
265264

266-
with codecs.open(tag_file, encoding="utf-8") as output:
265+
with open(tag_file, encoding="utf-8") as output:
267266
try:
268267
content = output.readlines()
269268
# there should be nothing in the file but headers (due to the
@@ -375,7 +374,7 @@ def test_parse_tag_lines__python(self):
375374

376375
tag_file = ctags.build_ctags(path=path, opts=["--python-kinds=-i"])
377376

378-
with codecs.open(tag_file, encoding="utf-8") as output:
377+
with open(tag_file, encoding="utf-8") as output:
379378
try:
380379
content = output.readlines()
381380
filename = os.path.basename(path)
@@ -471,7 +470,7 @@ def test_parse_tag_lines__c(self):
471470

472471
tag_file = ctags.build_ctags(path=path)
473472

474-
with codecs.open(tag_file, encoding="utf-8") as output:
473+
with open(tag_file, encoding="utf-8") as output:
475474
try:
476475
content = output.readlines()
477476
filename = os.path.basename(path)

0 commit comments

Comments
 (0)