|
|
Subscribe / Log in / New account

Growing pains for typing in Python

Growing pains for typing in Python

Posted Jan 18, 2024 17:08 UTC (Thu) by pizza (subscriber, #46)
In reply to: Growing pains for typing in Python by aigarius
Parent article: Growing pains for typing in Python

> As long as the objects have the methods that the other projects function is calling on them and those methods represent same kind of logical sense then it will just work

...except, of course, when it doesn't. Which is the entire point of this discussion.

BTW, the term for what you're referring to is "interfaces", and that is typically enforced by the same language mechanism that enforces typing. (It's routinely used in large/distributed Java environments in particular))


to post comments

Growing pains for typing in Python

Posted Jan 19, 2024 16:41 UTC (Fri) by aigarius (subscriber, #7329) [Link]

Funny thing that - external interfaces can not enforce anything and the behavior of functions of the same name can easily be different without breaking any interfaces. If we have a class A and a function B, that come from completely different projects that have never even heard about each other, then there will never be compatible type or interface definitions between them. So you, as the person bringing those two pieces together are the first one to try to map types or interfaces from one project to the other. All you are doing is writing down your opinion of whether those things are compatible or not. You can not enforce any of that - the way the function uses the methods of the interface or how the class implements the methods can change in ways that do not violate *their* type and interface definitions, but will violate *your* assumptions.

A person needs to determine if there is a *logical* sense in *how* function B is using methods on class A. No type system can tell you that.

And those can be really simple things, like sorting objects in ascending order or serialization them to JSON for RPC calls.

I just hit one such case today, that is broken right now inside the Python standard library. If you use pathlib Path objects and construct a complex, multilevel dict with the Path objects somewhere in the structure and then try to pass this structure to another server via jsonrpc call, well the whole thing comes crashing down because the Path objects are not JSON-serializable. Even if they are just used as a fancier proxy for simple text strings. If you use fancy types you get punished with fancy failures.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds