|
|
|
|
|
by orf
670 days ago
|
|
I can’t see how it would ever be possible with Python to do this. You depend on two packages, each with a function that returns a “requests.Request” object. These packages depend on different versions of “requests”. How would you implement “isinstance(return_value, requests.Request)” on each of these calls? Or, the indirect case of this: catching a “requests.HttpException” from each of these calls? Importing the right thing isn’t hard, but doing things with it is the hard bit. |
|
What you do with the return_value defines the behaviour you expect from it so to that extent you can rely on that instead of using isinstance:
Perhaps some function could build that Union type for you? It would be a pain to make it by hand if you had 50x different third-party dependencies each pulling in a slightly different requests (but which as far as you are concerned all return some small part of that package that are all compatible.)If you’re importing a module to use it in some way you’re also declaring some kind of version dependency / compatability on it too, so that’s another thing your static analysis could check for you. That would actually be incredibly useful:
1/ Do your dependencies import an older version of requests than you do?
2/ Does it matter, and why? (eg x.foo() only exists in version 4.5 onwards, but m1 imports 4.4.)