Skip to content

Commit a028634

Browse files
authored
Fix lint warnings for pylint 2.10 (#1459)
1 parent 7a94b68 commit a028634

9 files changed

+15
-11
lines changed

pygmt/helpers/tempfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def read(self, keep_tabs=False):
8484
content : str
8585
Content of the temporary file as a Unicode string.
8686
"""
87-
with open(self.name) as tmpfile:
87+
with open(self.name, mode="r", encoding="utf8") as tmpfile:
8888
content = tmpfile.read()
8989
if not keep_tabs:
9090
content = content.replace("\t", " ")

pygmt/sphinx_gallery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __call__(self, block, block_vars, gallery_conf):
2424
Called by sphinx-gallery to save the figures generated after running
2525
code.
2626
"""
27-
image_names = list()
27+
image_names = []
2828
image_path_iterator = block_vars["image_path_iterator"]
2929
figures = SHOWED_FIGURES
3030
while figures:

pygmt/tests/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_gmttempfile_read():
9393
Make sure GMTTempFile.read() works.
9494
"""
9595
with GMTTempFile() as tmpfile:
96-
with open(tmpfile.name, "w") as ftmp:
96+
with open(tmpfile.name, "w", encoding="utf8") as ftmp:
9797
ftmp.write("in.dat: N = 2\t<1/3>\t<2/4>\n")
9898
assert tmpfile.read() == "in.dat: N = 2 <1/3> <2/4>\n"
9999
assert tmpfile.read(keep_tabs=True) == "in.dat: N = 2\t<1/3>\t<2/4>\n"

pygmt/tests/test_legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_legend_specfile():
9393
"""
9494

9595
with GMTTempFile() as specfile:
96-
with open(specfile.name, "w") as file:
96+
with open(specfile.name, "w", encoding="utf8") as file:
9797
file.write(specfile_contents)
9898
fig = Figure()
9999
fig.basemap(projection="x6i", region=[0, 1, 0, 1], frame=True)

pygmt/tests/test_meca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_meca_spec_file():
169169
focal_mechanism = [-127.43, 40.81, 12, -3.19, 1.16, 3.93, -1.02, -3.93, -1.02, 23]
170170
# writes temp file to pass to gmt
171171
with GMTTempFile() as temp:
172-
with open(temp.name, mode="w") as temp_file:
172+
with open(temp.name, mode="w", encoding="utf8") as temp_file:
173173
temp_file.write(" ".join([str(x) for x in focal_mechanism]))
174174
# supply focal mechanisms to meca as a file
175175
fig.meca(

pygmt/tests/test_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_text_angle_font_justify_from_textfile():
289289
"""
290290
fig = Figure()
291291
with GMTTempFile(suffix=".txt") as tempfile:
292-
with open(tempfile.name, "w") as tmpfile:
292+
with open(tempfile.name, "w", encoding="utf8") as tmpfile:
293293
tmpfile.write("114 0.5 30 22p,Helvetica-Bold,black LM BORNEO")
294294
fig.text(
295295
region=[113, 117.5, -0.5, 3],

pygmt/tests/test_x2sys_cross.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def test_x2sys_cross_input_two_dataframes(mock_x2sys_home):
107107
)
108108

109109
# Add a time row to the x2sys fmtfile
110-
with open(file=os.path.join(tmpdir, "xyz.fmt"), mode="a") as fmtfile:
110+
with open(
111+
file=os.path.join(tmpdir, "xyz.fmt"), mode="a", encoding="utf8"
112+
) as fmtfile:
111113
fmtfile.write("time\ta\tN\t0\t1\t0\t%g\n")
112114

113115
# Create pandas.DataFrame track tables
@@ -164,7 +166,9 @@ def test_x2sys_cross_input_two_filenames(mock_x2sys_home):
164166
# Create temporary xyz files
165167
for i in range(2):
166168
np.random.seed(seed=i)
167-
with open(os.path.join(os.getcwd(), f"track_{i}.xyz"), mode="w") as fname:
169+
with open(
170+
os.path.join(os.getcwd(), f"track_{i}.xyz"), mode="w", encoding="utf8"
171+
) as fname:
168172
np.savetxt(fname=fname, X=np.random.rand(10, 3))
169173

170174
output = x2sys_cross(

pygmt/tests/test_x2sys_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_x2sys_init_region_spacing(mock_x2sys_home):
2929
tag=tag, fmtfile="xyz", force=True, region=[0, 10, 20, 30], spacing=[5, 5]
3030
)
3131

32-
with open(os.path.join(tmpdir, f"{tag}.tag"), "r") as tagpath:
32+
with open(os.path.join(tmpdir, f"{tag}.tag"), "r", encoding="utf8") as tagpath:
3333
tail_line = tagpath.readlines()[-1]
3434
assert "-R0/10/20/30" in tail_line
3535
assert "-I5/5" in tail_line
@@ -50,7 +50,7 @@ def test_x2sys_init_units_gap(mock_x2sys_home):
5050
gap=["tseconds", "de"],
5151
)
5252

53-
with open(os.path.join(tmpdir, f"{tag}.tag"), "r") as tagpath:
53+
with open(os.path.join(tmpdir, f"{tag}.tag"), "r", encoding="utf8") as tagpath:
5454
tail_line = tagpath.readlines()[-1]
5555
assert "-Nse -Nde" in tail_line
5656
assert "-Wtseconds -Wde" in tail_line

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
URL = "https://github.com/GenericMappingTools/pygmt"
1414
DESCRIPTION = "A Python interface for the Generic Mapping Tools"
1515
KEYWORDS = ""
16-
with open("README.rst") as f:
16+
with open("README.rst", "r", encoding="utf8") as f:
1717
LONG_DESCRIPTION = "".join(f.readlines())
1818

1919
PACKAGES = find_packages(exclude=["doc"])

0 commit comments

Comments
 (0)