Skip to content

Commit

Permalink
Merge pull request #1168 from akx/no-deprecation-warning-on-import
Browse files Browse the repository at this point in the history
Do not raise a DeprecationWarning in `stripe.app_info`
  • Loading branch information
pakrym-stripe authored Dec 11, 2023
2 parents 5ab12c6 + 980d4b5 commit e99ae54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
5 changes: 3 additions & 2 deletions stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions stripe/app_info.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e99ae54

Please sign in to comment.