Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 71afe0e

Browse files
committed
moved 2.20.* warnings into a proper Python PendingDeprecationWarning message
1 parent 89d76d9 commit 71afe0e

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .api_extras import api_extras
1919
from .api_decode_from_openapi import api_decode_from_openapi
2020
from .exceptions import CloudFlareAPIError, CloudFlareInternalError
21-
from .warning_2_20 import warning_2_20, print_warning_2_20
21+
from .warning_2_20 import warning_2_20, warn_warning_2_20, indent_warning_2_20
2222

2323
BASE_URL = 'https://api.cloudflare.com/client/v4'
2424
OPENAPI_URL = 'https://github.com/cloudflare/api-schemas/raw/main/openapi.json'
@@ -93,10 +93,11 @@ def __init__(self, config, warnings=True):
9393
# After 2.20.* there is a warning message posted to handle un-pinned versions
9494
warning = warning_2_20()
9595
if warning:
96+
# we are running 2.20.* or above and hence it's time to warn the user
9697
if self.logger:
97-
self.logger.warning(''.join(['\n ' + v for v in warning.split('\n')]))
98+
self.logger.warning(indent_warning_2_20(warning))
9899
else:
99-
print_warning_2_20(warning)
100+
warn_warning_2_20(indent_warning_2_20(warning))
100101

101102
def __del__(self):
102103
if self.network:

CloudFlare/warning_2_20.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" warning message if version is 2.20 or above (technically, there's no version above 2.20.0) """
22

33
import sys
4+
import warnings
45

56
from . import __version__
67

@@ -26,6 +27,19 @@ def warning_2_20():
2627
return None
2728
return MAJOR_VERSION_WARNING
2829

29-
def print_warning_2_20(warning):
30-
""" print_warning_2_20 """
31-
print(warning, file=sys.stderr)
30+
#def print_warning_2_20(warning):
31+
# """ print_warning_2_20 """
32+
# # boring stderr message printing - however, warn_ form is prefered
33+
# print(warning, file=sys.stderr)
34+
# pass
35+
36+
def warn_warning_2_20(warning):
37+
""" warn_warning_2_20 """
38+
# force these warnings to be shown (even if -Wd isn't used on python command line)
39+
warnings.simplefilter('always', PendingDeprecationWarning)
40+
# stacklevel=4 cleanly upstacks the calls in cloudflare.py (and hence should chanhge if cloudflare.py changes)
41+
warnings.warn(warning, PendingDeprecationWarning, stacklevel=4)
42+
43+
def indent_warning_2_20(warning):
44+
""" indent_warning_2_20 """
45+
return ''.join(['\n ' + v for v in warning.split('\n')])

0 commit comments

Comments
 (0)