Skip to content

Commit 75855cd

Browse files
committed
Upgraded to DeprecationWarning on ext config keyword.
Also checked for `None` so the existing extensions will at least still work. Of course, that code all gets deleted with the next release and things will break if extension authors do not update their code. Hope they test there code with each release and check for warnings. Also added a note to the release notes.
1 parent 044c0f2 commit 75855cd

File tree

2 files changed

+68
-18
lines changed

2 files changed

+68
-18
lines changed

docs/release-2.6.txt

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Backwards-incompatible Changes
5353
all except the `text` argument on the `markdown.markdown()` wrapper function.
5454
Using positional arguments will raise a **`DeprecationWarning`** in 2.6 and an error
5555
in version 2.7. Only keyword arguments should be used. For example, if your code
56-
previosuly looked like this:
56+
previously looked like this:
5757

5858
html = markdown.markdown(text, [SomeExtension()])
5959

@@ -65,11 +65,11 @@ Backwards-incompatible Changes
6565
This change is being made as a result of deprecating `"safe_mode"` as the
6666
`safe_mode` argument was one of the positional arguments. When that argument
6767
is removed, the two arguments following it will no longer be at the correct
68-
position. It is recomended that you always use keywords when they are supported
68+
position. It is recommended that you always use keywords when they are supported
6969
for this reason.
7070

71-
* In previous versions of Python-Markdown, the builtin extensions received
72-
special status and did not require the full path to be provided. Additionaly,
71+
* In previous versions of Python-Markdown, the built-in extensions received
72+
special status and did not require the full path to be provided. Additionally,
7373
third party extensions whose name started with "mdx_" received the same
7474
special treatment. This behavior is deprecated and will raise a
7575
**`DeprecationWarning`** in version 2.6 and an error in 2.7. Ensure that you
@@ -86,15 +86,15 @@ Backwards-incompatible Changes
8686

8787
$ python -m markdown -x markdown.extensions.extra input.txt
8888

89-
See the [documentation](reference.html#extensions) for a full explaination
89+
See the [documentation](reference.html#extensions) for a full explanation
9090
of the current behavior.
9191

9292
* The previously documented method of appending the extension configs as
9393
a string to the extension name is deprecated and will raise a
9494
**`DeprecationWarning`** in version 2.6 and an error in 2.7.
9595
The [extension_configs](reference.html#extension_configs) keyword should
9696
be used instead. See the [documentation](reference.html#extension-configs)
97-
for a full explaination of the current behavior.
97+
for a full explanation of the current behavior.
9898

9999
* The [HeaderId][hid] Extension is pending deprecation and will raise a
100100
**`PendingDeprecationWarning`** in version 2.6. The extension will be
@@ -109,11 +109,59 @@ Backwards-incompatible Changes
109109

110110
[hid]: extensions/header_id.html
111111

112+
* Positional arguments and the `configs` keyword on the `markdown.extension.Extension` class
113+
(and its subclasses) are deprecated. Each individual config option should be passed
114+
to the class as a keyword/value pair. For example. one might have previously initiated
115+
an extension subclass like this:
116+
117+
ext = SomeExtension(configs={'somekey': 'somevalue'})
118+
119+
That code should be updated to pass in the options directly:
120+
121+
ext = SomeExtension(somekey='somevalue')
122+
123+
Extension authors will want to note that this affects the `makeExtension` function as well.
124+
Previously it was common for the function to be defined as follows:
125+
126+
def makeExtension(configs=None):
127+
return SomeExtension(configs=configs)
128+
129+
Extension authors will want to update their code to the following instead:
130+
131+
def makeExtension(**kwargs):
132+
return SomeExtension(**kwargs)
133+
134+
Failing to do so will result in a DeprecationWarning and will raise an error in the next
135+
release. See the [Extension API][mext] documentation for more information.
136+
137+
In the event that an `markdown.extension.Extension` subclass overrides the `__init__` method
138+
and implements its own config handling, then the above may not apply. However, it is
139+
recommended that the subclass still calls the parent `__init__` method to handle configs
140+
like so:
141+
142+
class SomeExtension(markdown.extension.Extension):
143+
def __init__(**kwargs):
144+
# Do pre-config stuff here
145+
# Set config defaults
146+
self.config = {
147+
'option1' : ['value1', 'description1'],
148+
'option2' : ['value2', 'description2']
149+
}
150+
# Set user defined configs
151+
super(MyExtension, self).__init__(**kwargs)
152+
# Do post-config stuff here
153+
154+
Note the call to `super` to get the benefits of config handling from the parent class.
155+
See the [documentation][config] for more information.
156+
157+
[config]: extensions/api.html#configsettings
158+
[mext]: extensions/api.html#makeextension
159+
112160
What's New in Python-Markdown 2.6
113161
---------------------------------
114162

115163
* Official support for [PyPy] has been added. While Python-Markdown has most likely
116-
worked on PyPy for some time, it is now offically supported and tested on PyPy.
164+
worked on PyPy for some time, it is now officially supported and tested on PyPy.
117165

118166
[PyPy]: http://pypy.org/
119167

@@ -129,7 +177,7 @@ worked on PyPy for some time, it is now offically supported and tested on PyPy.
129177
[YAML]: http://yaml.org/
130178

131179
* The [Table fo Contents][TOC] Extension has been refactored and some new features
132-
have been added. See the documentation for a full explaination of each feature
180+
have been added. See the documentation for a full explanation of each feature
133181
listed below:
134182

135183
* The extension now assigns the Table of Contents to the `toc` attribute of
@@ -150,7 +198,7 @@ worked on PyPy for some time, it is now offically supported and tested on PyPy.
150198

151199
* A `baselevel` config option has been added allowing users to set the base level
152200
of headers in their documents (h1-h6). This allows the header levels to be
153-
automatically adjusted to fit within the hierarchy of an html template.
201+
automatically adjusted to fit within the hierarchy of an HTML template.
154202

155203
[TOC]: extensions/toc.html
156204

markdown/extensions/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,27 @@ def __init__(self, *args, **kwargs):
2626
# check for configs arg for backward compat.
2727
# (there only ever used to be one so we use arg[0])
2828
if len(args):
29-
self.setConfigs(args[0])
29+
if args[0] is not None:
30+
self.setConfigs(args[0])
3031
warnings.warn('Extension classes accepting positional args is '
3132
'pending Deprecation. Each setting should be '
3233
'passed into the Class as a keyword. Positional '
33-
'args will be deprecated in version 2.6 and raise '
34+
'args are deprecated and will raise '
3435
'an error in version 2.7. See the Release Notes for '
35-
'Python-Markdown version 2.5 for more info.',
36-
PendingDeprecationWarning)
36+
'Python-Markdown version 2.6 for more info.',
37+
DeprecationWarning)
3738
# check for configs kwarg for backward compat.
3839
if 'configs' in kwargs.keys():
39-
self.setConfigs(kwargs.pop('configs', {}))
40+
if kwargs['configs'] is not None:
41+
self.setConfigs(kwargs.pop('configs', {}))
4042
warnings.warn('Extension classes accepting a dict on the single '
4143
'keyword "config" is pending Deprecation. Each '
4244
'setting should be passed into the Class as a '
43-
'keyword directly. The "config" keyword will be '
44-
'deprecated in version 2.6 and raise an error in '
45+
'keyword directly. The "config" keyword is '
46+
'deprecated and raise an error in '
4547
'version 2.7. See the Release Notes for '
46-
'Python-Markdown version 2.5 for more info.',
47-
PendingDeprecationWarning)
48+
'Python-Markdown version 2.6 for more info.',
49+
DeprecationWarning)
4850
# finally, use kwargs
4951
self.setConfigs(kwargs)
5052

0 commit comments

Comments
 (0)