feat(ports): add null checks for port name in short name generation

Add conditional checks to ensure `self._name` is not None before performing string operations in the `short_name` property. This prevents potential AttributeError exceptions when port name is undefined, improving robustness and compatibility with edge cases in port configuration.
This commit is contained in:
YueGuobin 2026-02-25 22:21:05 +08:00
parent 4519130a8c
commit f6777064db

View File

@ -83,9 +83,9 @@ class Port:
# If port name format has changed we use the port name as the short name (1.X behavior)
if self._short_name:
return self._short_name
elif "/" in self._name:
elif self._name and "/" in self._name:
return self._name.replace(self.long_name_type(), self.short_name_type())
elif self._name.startswith(f"{self.long_name_type()}{self._interface_number}"):
elif self._name and self._name.startswith(f"{self.long_name_type()}{self._interface_number}"):
return self.short_name_type() + f"{self._interface_number}"
return self._name