From c87be89e074d496f7219d10bdbc3cf4ac2b3bc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20M=C3=A5rtensson?= Date: Wed, 29 Apr 2020 10:29:44 +0200 Subject: [PATCH] Fix #353 - String representation of network elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the string representation of some elements in elements.py refer to parameters that are not assigned until the propagate function runs. Printing an element or trying to access its string representation before propagation therefore raises a TypeError. This patch should fix the issue. Change-Id: I29962f3c00e1f4fb7935535d4514a9579bc0c918 Signed-off-by: Jonas MÃ¥rtensson --- gnpy/core/elements.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gnpy/core/elements.py b/gnpy/core/elements.py index 76357019..3ba88213 100644 --- a/gnpy/core/elements.py +++ b/gnpy/core/elements.py @@ -147,6 +147,9 @@ class Roadm(Node): return f'{type(self).__name__}(uid={self.uid!r}, loss={self.loss!r})' def __str__(self): + if self.effective_loss is None: + return f'{type(self).__name__} {self.uid}' + return '\n'.join([f'{type(self).__name__} {self.uid}', f' effective loss (dB): {self.effective_loss:.2f}', f' pch out (dBm): {self.effective_pch_out_db!r}']) @@ -233,6 +236,7 @@ class Fiber(Node): super().__init__(*args, params=FiberParams(**params), **kwargs) self.carriers_in = None self.carriers_out = None + self.pch_out_db = None self.nli_solver = NliSolver(self) @property @@ -260,6 +264,9 @@ class Fiber(Node): f'loss={round(self.loss,1)!r}dB)' def __str__(self): + if self.pch_out_db is None: + return f'{type(self).__name__} {self.uid}' + return '\n'.join([f'{type(self).__name__} {self.uid}', f' type_variety: {self.type_variety}', f' length (km): '