[reportlab-users] [reportlab-support] ReportLab Pylance Bug
Robin Becker
robin at reportlab.com
Fri Sep 9 04:39:51 EDT 2022
On 09/09/2022 01:31, Natalie Jackson wrote:
> bschnurr <https://github.com/bschnurr> commented 1 minute ago
> <https://github.com/microsoft/pylance-release/issues/3270#issuecomment-1241364028>
>
> I can't remember what kind of exception they throw, but if they throw
> 'UnimplementedError' in the base applyStateChanges instead then we should
> also not treat it as no return.
>
>
,,,,,,,
I'm afraid I will not be adding any decorators to methods to assist any specific analysis tool.
The tool's analysis is just wrong. The _PDFRenderer.draw method is Render.draw is true, but the methods called by that
method are those of _PDFRenderer. I made a small example see at end. Does pylance really think that the final print is
unreachable>? If it does then presumable it doesn't understand that the self in methods may refer to a derived class.
Presumably pylance is unable to figure out that the child class implements some or all of the methods in the base which
it thinks will cause an exception.
The observed truth is that the _PDFrenderer draw method does not always raise an exception.
############################################################
if __name__=='__main__':
class B:
def draw(self):
print(f'B.draw {self.draw}')
self.applyStateChanges()
def undefined(self, operation):
print(f'B.undefined {self.undefined}')
raise ValueError(f'{undefined} in {self.__class__}')
def applyStateChanges(self):
print(f'B.applyStateChanges {self.applyStateChanges}')
self.undefined('applyStateChanges')
class D(B):
def applyStateChanges(self):
print(f'D.applyStateChanges {self.applyStateChanges}')
def draw():
d = D()
d.draw()
draw()
print('draw was called and did not raise an exception')
############################################################
--
Robin Becker
More information about the reportlab-users
mailing list