[Twisted-Python] Inheriting DatagramProtocol, which is an old-style class
![](https://secure.gravatar.com/avatar/bf006aac4f248c75a22c3446679235d6.jpg?s=120&d=mm&r=g)
I am creating a child class `Child(twisted.internet.protocol.DatagramProtocol)` to implement a custom UDP multicast protocol. I need to add an `__init__()` to `Child`, but as part of that I need to call `super()` which is impossible because `DatagramProtocol` is old-style. How should I proceed? Also, why are there old-style classes in the latest release of Twisted?
![](https://secure.gravatar.com/avatar/fbd473e7e3b6675a84cd3c3b4a2c1972.jpg?s=120&d=mm&r=g)
On Saturday, 8 February 2020 01:50:04 CET Go Luhng wrote:
There is no __init__() in DatagramProtocol or in its superclass AbstractDatagramProtocol, so you can just skip the call.
Also, why are there old-style classes in the latest release of Twisted?
I don't know the reason, but it seems to be deliberate, since AbstractDatagramProtocol is annotated with @_oldStyle in the source. Bye, Maarten
![](https://secure.gravatar.com/avatar/bcb6ef473ff1644fddee1b4e7c730b01.jpg?s=120&d=mm&r=g)
Old-style classes remain old-style for compatibility reasons. You have some options, though: 1. Set the TWISTED_NEWSTYLE environment variable [1] to make all such old-style classes new-style. 2. When subclassing it, also subclass object, making the result new-style. 3. Switch to Python 3, where all-classes are new-style. Option 3 is the best, since we will drop Python 2.7 support soon enough. Option 1 may be helpful when migrating a codebase. ---Tom [1]: https://github.com/twisted/twisted/blob/c0a51509974e995537212efc507414038858... On Fri, Feb 7, 2020, at 9:44 PM, Maarten ter Huurne wrote:
![](https://secure.gravatar.com/avatar/fbd473e7e3b6675a84cd3c3b4a2c1972.jpg?s=120&d=mm&r=g)
On Saturday, 8 February 2020 01:50:04 CET Go Luhng wrote:
There is no __init__() in DatagramProtocol or in its superclass AbstractDatagramProtocol, so you can just skip the call.
Also, why are there old-style classes in the latest release of Twisted?
I don't know the reason, but it seems to be deliberate, since AbstractDatagramProtocol is annotated with @_oldStyle in the source. Bye, Maarten
![](https://secure.gravatar.com/avatar/bcb6ef473ff1644fddee1b4e7c730b01.jpg?s=120&d=mm&r=g)
Old-style classes remain old-style for compatibility reasons. You have some options, though: 1. Set the TWISTED_NEWSTYLE environment variable [1] to make all such old-style classes new-style. 2. When subclassing it, also subclass object, making the result new-style. 3. Switch to Python 3, where all-classes are new-style. Option 3 is the best, since we will drop Python 2.7 support soon enough. Option 1 may be helpful when migrating a codebase. ---Tom [1]: https://github.com/twisted/twisted/blob/c0a51509974e995537212efc507414038858... On Fri, Feb 7, 2020, at 9:44 PM, Maarten ter Huurne wrote:
participants (3)
-
Go Luhng
-
Maarten ter Huurne
-
Tom Most