Latest Tech News

Stay updated with the latest in technology, AI, cybersecurity, and more

Filtered by: subclasses Clear Filter

Use keyword-only arguments in Python dataclasses

Python dataclasses are a really nice feature for constructing classes that primarily hold or work with data. They can be a good alternative to using dictionaries, since they allow you to add methods, dynamic properties, and subclasses. They can also be a good alternative to building your own class by hand, since they don’t need a custom __init__() that reassigns attributes and provide methods like __eq__() out of the box. One small tip to keeping dataclasses maintainable is to always construct

Public/protected/private is an unnecessary feature

public/protected/private is an unnecessary feature Regular code using this interface works great: Users can write generic code that works for any Vehicle, and use a Car with that code. The implementer of Car can restrict users to only ever use Car instances through the Vehicle interface, by only allowing construction of Car instances through, for example, a function make_car with return type Vehicle. But the interface doesn't work with inheritance: Users cannot write a generic class that can i