You need to follow the terms of the license(s).1
1Honestly, that's it.
For the licenses you cite (BSD, MIT) there is nothing within the license terms that say you must use the entire module. In fact, both of those licenses give you explicit permission to do what you're suggesting.
including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software
Redistribution and use in source and binary forms, with or without modification, are permitted ...
So go ahead and take those functions out of those modules that you want in order to avoid creating a dependency upon a whole library.
But what you can't do is fail to attribute the source of the code you used. Both licenses require that you include a copy of the license as well as the copyright notice.
That may mean you need to put a prolog around the modules you copy and provide copyright attribution. Or you may have to modify the license files to explicitly call out what portions of your code were sourced from where. It's going to depend upon your project and the extent of how much you borrowed.
You also said:
The safe way would be to always ask the upstream author what does he want
But that's not quite true. The upstream author has already expressly told you their intent through the license terms that they have released their code under. You only need to contact the upstream author if you want to do something outside of the terms of the license.