[Python] Why early imports to populate sys.module

Discussão em 'Python' iniciado por Stack, Fevereiro 8, 2025.

  1. Stack

    Stack Membro Participativo

    https://github.com/stripe/stripe-python/blob/master/stripe/__init__.py

    # We must import the app_info module early to populate it into
    # `sys.modules`; otherwise doing `import stripe.app_info` will end up
    # importing that module, and not the global `AppInfo` name from below.
    import stripe.app_info
    from stripe._app_info import AppInfo as AppInfo
    from stripe._version import VERSION as VERSION


    What is mean by stripe.app_info must be imported early to prevent AppInfo from being imported? AppInfo isnt even located in stripe.app_info but in stripe._app_info?

    Tried ChatGPT, they say its something related to defensive programming to prevent bugs.

    Continue reading...

Compartilhe esta Página