Python is a programming language common in the data science space. Here is a list of gotchas that I have encountered while using it, coming from a Java world.
Static checkers are okay, but the runtime type system is pretty weak. There is no equivalent of type capture in Java (e.g. static <T> List<T> makeList(T item) {…}
throws if the second arg is a generic type. For example isinstance(var, dict[str, Any]). This is annoying because you only find out at runtime that it's broken.
Trying to implement Java's ThreadPoolExecutor needs more diverse Queue implementations.
queue.Queue throws exceptions when the queue is empty, rather than returning Nonequeue.Queue calls can't be interrupted.SynchronousQueue in Java. This class is the key to a cached ThreadPoolExecutor.queue.SimpleQueue timeout doesn't work. The task-tracking part of Queue and the timeout handling come as a package deal, meaning you get both or neither.Caching comes in many forms, but one surprising way that it shows up is in connection caching (a.k.a. pooling). Without special handling, connections cannot be shared between processes. When a Python program spawns another process, the new process does not inherit the file descriptors (fds) and thus has to re create them itself. This has many problems:
Multiprocessing skips the atexit hooks, meaning it's not possible to do process-wide cleanup work. They are silently skipped.
Evaluation order matters. For example:
a: Descriptor b: Descriptor foo(a, b)
In this, if a or b have side-effects on evaluation, like throwing an exception, the order in which a and b are invoked matters.