Commit 4324104
committed
refactor: Make SysUtil.link_info_find() more pythonic
The existing implementation of `link_info_find()` had several issues
that made it error-prone and harder to maintain:
- The refresh parameter was unused, adding unnecessary complexity.
- MAC address matching logic was convoluted, with redundant variables
and conditions.
- The use of locals() for fallback results was unclear and could lead to
subtle bugs.
- The order of checks (MAC vs ifname) didn't prioritize the most
reliable matching criteria.
To address these issues, the following changes were made:
- Removed the unused `refresh` argument to reduce complexity.
- Used `None` checks more idiomatically with `if mac` instead of `is not
None`.
- Eliminated redundant variables and conditions to improve readability.
- Avoided using `locals()` by explicitly storing fallback results.
- Made `ifname` matching take priority before checking MAC addresses.
- Ensured that the function returns early when a definitive match is
found.
Signed-off-by: Wen Liang <[email protected]>1 parent 53be949 commit 4324104
1 file changed
+17
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | | - | |
226 | | - | |
| 226 | + | |
| 227 | + | |
227 | 228 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 229 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 230 | + | |
236 | 231 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
241 | 235 | | |
242 | | - | |
243 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
244 | 239 | | |
245 | | - | |
246 | | - | |
247 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
248 | 246 | | |
249 | | - | |
| 247 | + | |
250 | 248 | | |
251 | 249 | | |
252 | 250 | | |
| |||
0 commit comments