It's a fairly standard pattern to see things like this:
try:import fooexcept ImportError:foo = None
It's a fairly standard pattern to see things like this:try:import fooexcept ImportError:foo = None(and of course, variants with from...import et cetera). These can potentially add a lot of clutter to the imports section of a file, given that it requires 4 lines to do a conditional import.It seems like it'd be useful and clean to have a syntax that looked like this:maybe import foofrom bar maybe import bazfrom qux maybe import quy as quzWhere the behavior would essentially be as above - attempt to run the import normally, and in cases where the import fails, map the name to a value of None instead. Users who want a different behavior are still free to use the long-form syntax. A possibly variant might be to also only run the import if the name isn't already bound, so that you could do something like...from frobber_a maybe import frob as frobberfrom frobbler_b maybe import frobble as frobberfrom frobber_c maybe import frobit as frobber...to potentially try different fallback options if the first choice for an interface provider isn't available._______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/