3 ms·
Even better is ... just not breaking the interface, leave the code be. Add parameters at the end. Or just add a new function. Or even a new module if things ge
by Lutger 1y ago
Even better is ... just not breaking the interface, leave the code be.
Add parameters at the end. Or just add a new function. Or even a new module if things get too messy for your liking.
Just leave the old users in peace. If you are worried about breaking stuff, it means people are using the function you wrote and find value in it. Why change it at all? I think it is very rare that the reasons for breaking are so compelling that they are worth the trouble.
- ziml77 1y agoBut the problem here is that with a dataclass you never explicitly defined any parameters. It's the dataclass annotation that defined them for the constructor based on the order of the fields. So, yes the solution is to never re-order the fields and only add new ones to the end, but this can be a surprising requirement because normally the order of fields in a class doesn't matter to users of the class.