diff --git a/.flake8 b/.flake8 index 82e14fd6b..5b99098ec 100644 --- a/.flake8 +++ b/.flake8 @@ -27,6 +27,10 @@ per-file-ignores = stripe/oauth_error.py: IMP102 # setup.py is required for tooling setup.py: IMP102 + # should not raise a deprecation warning since it needs + # to be imported early in `stripe/__init__.py` to avoid + # a name conflict + stripe/app_info.py: IMP102 [flake8:local-plugins] extension = diff --git a/stripe/__init__.py b/stripe/__init__.py index b235ae00c..1e0e5c8ad 100644 --- a/stripe/__init__.py +++ b/stripe/__init__.py @@ -13,8 +13,9 @@ # Configuration variables from stripe._api_version import _ApiVersion -# We must import the app_info module eagerly before defining the app_info global -# otherwise the late import will overwrite the global +# 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 diff --git a/stripe/app_info.py b/stripe/app_info.py index 44844cdca..44b9fe99d 100644 --- a/stripe/app_info.py +++ b/stripe/app_info.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- +""" +The stripe.app_info package is deprecated, please change your +imports to import from stripe directly. +From: + from stripe.app_info import AppInfo +To: + from stripe import AppInfo +""" from typing_extensions import TYPE_CHECKING -from warnings import warn -warn( - """ - The stripe.app_info package is deprecated, please change your - imports to import from stripe directly. - From: - from stripe.app_info import AppInfo - To: - from stripe import AppInfo - """, - DeprecationWarning, -) +# No deprecation warning is raised here, because it would happen +# on every import of `stripe/__init__.py` otherwise. Since that +# module declares its own `app_info` name, this module becomes +# practically impossible to import anyway. if not TYPE_CHECKING: from stripe._app_info import ( # noqa