Skip to content

Commit fbc9506

Browse files
committed
Remove unecessary file close
1 parent 31a4811 commit fbc9506

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

adafruit_platformdetect/__init__.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ def get_cpuinfo_field(self, field):
4848

4949
with open("/proc/cpuinfo", "r") as infile:
5050
cpuinfo = infile.read().split("\n")
51-
infile.close()
52-
for line in cpuinfo:
53-
match = re.search(pattern, line, flags=re.IGNORECASE)
54-
if match:
55-
return match.group(1)
56-
return None
51+
for line in cpuinfo:
52+
match = re.search(pattern, line, flags=re.IGNORECASE)
53+
if match:
54+
return match.group(1)
5755

5856
def check_dt_compatible_value(self, value):
5957
"""
@@ -82,7 +80,6 @@ def get_armbian_release_field(self, field):
8280
match = re.search(pattern, line)
8381
if match:
8482
field_value = match.group(1)
85-
release_file.close()
8683
except FileNotFoundError:
8784
pass
8885

@@ -93,60 +90,40 @@ def get_device_model(self):
9390
Search /proc/device-tree/model for the device model and return its value, if found,
9491
otherwise None.
9592
"""
96-
model = None
97-
9893
try:
9994
with open("/proc/device-tree/model", "r") as model_file:
100-
model = model_file.read()
101-
model_file.close()
95+
return model_file.read()
10296
except FileNotFoundError:
10397
pass
10498

105-
return model
106-
10799
def get_device_compatible(self):
108100
"""
109101
Search /proc/device-tree/compatible for the compatible chip name.
110102
"""
111-
model = None
112-
113103
try:
114104
with open("/proc/device-tree/compatible", "r") as model_file:
115-
model = model_file.read()
116-
model_file.close()
105+
return model_file.read()
117106
except FileNotFoundError:
118107
pass
119108

120-
return model
121-
122109
def check_board_asset_tag_value(self):
123110
"""
124111
Search /sys/devices/virtual/dmi/id for the device model and return its value, if found,
125112
otherwise None.
126113
"""
127-
tag = None
128-
129114
try:
130115
with open("/sys/devices/virtual/dmi/id/board_asset_tag", "r") as tag_file:
131-
tag = tag_file.read().strip()
132-
tag_file.close()
116+
return tag_file.read().strip()
133117
except FileNotFoundError:
134118
pass
135119

136-
return tag
137-
138120
def check_board_name_value(self):
139121
"""
140122
Search /sys/devices/virtual/dmi/id for the board name and return its value, if found,
141123
otherwise None. Debian/ubuntu based
142124
"""
143-
board_name = None
144-
145125
try:
146126
with open("/sys/devices/virtual/dmi/id/board_name", "r") as board_name_file:
147-
board_name = board_name_file.read().strip()
148-
board_name.close()
127+
return board_name_file.read().strip()
149128
except FileNotFoundError:
150129
pass
151-
152-
return board_name

0 commit comments

Comments
 (0)