[Twisted-Python] Question about FileDescriptor.loseConnection() signature found by mypy

Maarten ter Huurne maarten at treewalker.org
Tue Jun 16 06:01:05 MDT 2020


On Tuesday, 16 June 2020 10:51:21 CEST Glyph wrote:
> > On Jun 15, 2020, at 8:43 PM, Craig Rodrigues
> > <rodrigc at crodrigues.org> wrote:
> > 
> > In twisted.internet.abstract.FileDescriptor.loseConnection, the
> > loseConnection method> 
> > is defined like:
> >     def loseConnection(self, 
_connDone=failure.Failure(main.CONNECTION_DONE)):
> I think this signature might just be... wrong?  ITransport doesn't
> include it.  Does anything actually use this argument?

I think this isn't actually an argument: the underscore in the name 
suggests it is not part of the interface. What seems to be happening 
here is that twisted.internet.abstract.FileDescriptor.loseConnection 
defines a constant by putting it in an argument default value.

A simple solution would be to replace it by a class-scope or module-
scope constant.


By the way, is it valid to wrap an exception that was never raised in a 
Failure object? Because that is what happens here by reusing the single 
_connDone instance. It seems Failure's implementation is prepared to 
handle it, but its docstring doesn't mention it.

Bye,
		Maarten





More information about the Twisted-Python mailing list