From 7637fb6c85ae753616046c1d4c9b23b56c8cdf57 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sat, 13 Jan 2018 16:13:07 -0500 Subject: Remove deprecated support for Extension args. In the past Markdown used to pass extension config settings to the Extension class via a positional argument named `config`. That was deprecated in 2.6 in favor of using keyword arguments (`**kwargs`). Support has been completely dropped. Only keyword arguments are accepted. --- markdown/extensions/__init__.py | 29 +---------------------------- markdown/extensions/abbr.py | 4 ++-- markdown/extensions/admonition.py | 4 ++-- markdown/extensions/attr_list.py | 4 ++-- markdown/extensions/codehilite.py | 8 ++++---- markdown/extensions/def_list.py | 4 ++-- markdown/extensions/extra.py | 9 ++++----- markdown/extensions/fenced_code.py | 4 ++-- markdown/extensions/footnotes.py | 8 ++++---- markdown/extensions/meta.py | 4 ++-- markdown/extensions/nl2br.py | 4 ++-- markdown/extensions/sane_lists.py | 4 ++-- markdown/extensions/smart_strong.py | 4 ++-- markdown/extensions/smarty.py | 8 ++++---- markdown/extensions/tables.py | 4 ++-- markdown/extensions/toc.py | 8 ++++---- markdown/extensions/wikilinks.py | 8 ++++---- 17 files changed, 45 insertions(+), 73 deletions(-) diff --git a/markdown/extensions/__init__.py b/markdown/extensions/__init__.py index 6e7a08a..1e33a14 100644 --- a/markdown/extensions/__init__.py +++ b/markdown/extensions/__init__.py @@ -5,7 +5,6 @@ Extensions from __future__ import unicode_literals from ..util import parseBoolValue -import warnings class Extension(object): @@ -20,34 +19,8 @@ class Extension(object): # if a default is not set here. config = {} - def __init__(self, *args, **kwargs): + def __init__(self, **kwargs): """ Initiate Extension and set up configs. """ - - # check for configs arg for backward compat. - # (there only ever used to be one so we use arg[0]) - if len(args): - if args[0] is not None: - self.setConfigs(args[0]) - warnings.warn('Extension classes accepting positional args is ' - 'pending Deprecation. Each setting should be ' - 'passed into the Class as a keyword. Positional ' - 'args are deprecated and will raise ' - 'an error in version 2.7. See the Release Notes for ' - 'Python-Markdown version 2.6 for more info.', - DeprecationWarning) - # check for configs kwarg for backward compat. - if 'configs' in kwargs.keys(): - if kwargs['configs'] is not None: - self.setConfigs(kwargs.pop('configs', {})) - warnings.warn('Extension classes accepting a dict on the single ' - 'keyword "config" is pending Deprecation. Each ' - 'setting should be passed into the Class as a ' - 'keyword directly. The "config" keyword is ' - 'deprecated and raise an error in ' - 'version 2.7. See the Release Notes for ' - 'Python-Markdown version 2.6 for more info.', - DeprecationWarning) - # finally, use kwargs self.setConfigs(kwargs) def getConfig(self, key, default=''): diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py index e6aff7b..2553aac 100644 --- a/markdown/extensions/abbr.py +++ b/markdown/extensions/abbr.py @@ -90,5 +90,5 @@ class AbbrPattern(Pattern): return abbr -def makeExtension(*args, **kwargs): # pragma: no cover - return AbbrExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return AbbrExtension(**kwargs) diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index 1ac4a20..8576638 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -92,5 +92,5 @@ class AdmonitionProcessor(BlockProcessor): return klass, title -def makeExtension(*args, **kwargs): # pragma: no cover - return AdmonitionExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return AdmonitionExtension(**kwargs) diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py index ea36d37..76b7d99 100644 --- a/markdown/extensions/attr_list.py +++ b/markdown/extensions/attr_list.py @@ -168,5 +168,5 @@ class AttrListExtension(Extension): ) -def makeExtension(*args, **kwargs): # pragma: no cover - return AttrListExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return AttrListExtension(**kwargs) diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index e30c7ba..fed4d64 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -227,7 +227,7 @@ class HiliteTreeprocessor(Treeprocessor): class CodeHiliteExtension(Extension): """ Add source code hilighting to markdown codeblocks. """ - def __init__(self, *args, **kwargs): + def __init__(self, **kwargs): # define default configs self.config = { 'linenums': [None, @@ -249,7 +249,7 @@ class CodeHiliteExtension(Extension): 'Default: True'] } - super(CodeHiliteExtension, self).__init__(*args, **kwargs) + super(CodeHiliteExtension, self).__init__(**kwargs) def extendMarkdown(self, md, md_globals): """ Add HilitePostprocessor to Markdown instance. """ @@ -260,5 +260,5 @@ class CodeHiliteExtension(Extension): md.registerExtension(self) -def makeExtension(*args, **kwargs): # pragma: no cover - return CodeHiliteExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return CodeHiliteExtension(**kwargs) diff --git a/markdown/extensions/def_list.py b/markdown/extensions/def_list.py index cbbffdc..a79c1c1 100644 --- a/markdown/extensions/def_list.py +++ b/markdown/extensions/def_list.py @@ -111,5 +111,5 @@ class DefListExtension(Extension): '>ulist') -def makeExtension(*args, **kwargs): # pragma: no cover - return DefListExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return DefListExtension(**kwargs) diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py index 33ee4b2..d1294e0 100644 --- a/markdown/extensions/extra.py +++ b/markdown/extensions/extra.py @@ -50,10 +50,9 @@ extensions = [ class ExtraExtension(Extension): """ Add various extensions to Markdown class.""" - def __init__(self, *args, **kwargs): + def __init__(self, **kwargs): """ config is a dumb holder which gets passed to actual ext later. """ - self.config = kwargs.pop('configs', {}) - self.config.update(kwargs) + self.config = kwargs def extendMarkdown(self, md, md_globals): """ Register extension instances. """ @@ -68,8 +67,8 @@ class ExtraExtension(Extension): r'^(p|h[1-6]|li|dd|dt|td|th|legend|address)$', re.IGNORECASE) -def makeExtension(*args, **kwargs): # pragma: no cover - return ExtraExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return ExtraExtension(**kwargs) class MarkdownInHtmlProcessor(BlockProcessor): diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 01aa605..e1a616e 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -109,5 +109,5 @@ class FencedBlockPreprocessor(Preprocessor): return txt -def makeExtension(*args, **kwargs): # pragma: no cover - return FencedCodeExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return FencedCodeExtension(**kwargs) diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index 6ac92ab..d16cf84 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -35,7 +35,7 @@ RE_REF_ID = re.compile(r'(fnref)(\d+)') class FootnoteExtension(Extension): """ Footnote Extension. """ - def __init__(self, *args, **kwargs): + def __init__(self, **kwargs): """ Setup configs. """ self.config = { @@ -56,7 +56,7 @@ class FootnoteExtension(Extension): "of the backlink. %d will be replaced by the " "footnote number."] } - super(FootnoteExtension, self).__init__(*args, **kwargs) + super(FootnoteExtension, self).__init__(**kwargs) # In multiple invocations, emit links that don't get tangled. self.unique_prefix = 0 @@ -426,6 +426,6 @@ class FootnotePostprocessor(Postprocessor): return text.replace(NBSP_PLACEHOLDER, " ") -def makeExtension(*args, **kwargs): # pragma: no cover +def makeExtension(**kwargs): # pragma: no cover """ Return an instance of the FootnoteExtension """ - return FootnoteExtension(*args, **kwargs) + return FootnoteExtension(**kwargs) diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py index 33e13fb..cafad4a 100644 --- a/markdown/extensions/meta.py +++ b/markdown/extensions/meta.py @@ -74,5 +74,5 @@ class MetaPreprocessor(Preprocessor): return lines -def makeExtension(*args, **kwargs): # pragma: no cover - return MetaExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return MetaExtension(**kwargs) diff --git a/markdown/extensions/nl2br.py b/markdown/extensions/nl2br.py index 1d23c99..687d1eb 100644 --- a/markdown/extensions/nl2br.py +++ b/markdown/extensions/nl2br.py @@ -31,5 +31,5 @@ class Nl2BrExtension(Extension): md.inlinePatterns.add('nl', br_tag, '_end') -def makeExtension(*args, **kwargs): # pragma: no cover - return Nl2BrExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return Nl2BrExtension(**kwargs) diff --git a/markdown/extensions/sane_lists.py b/markdown/extensions/sane_lists.py index 4b118af..89f929f 100644 --- a/markdown/extensions/sane_lists.py +++ b/markdown/extensions/sane_lists.py @@ -51,5 +51,5 @@ class SaneListExtension(Extension): md.parser.blockprocessors['ulist'] = SaneUListProcessor(md.parser) -def makeExtension(*args, **kwargs): # pragma: no cover - return SaneListExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return SaneListExtension(**kwargs) diff --git a/markdown/extensions/smart_strong.py b/markdown/extensions/smart_strong.py index 7070318..1b00f84 100644 --- a/markdown/extensions/smart_strong.py +++ b/markdown/extensions/smart_strong.py @@ -37,5 +37,5 @@ class SmartEmphasisExtension(Extension): ) -def makeExtension(*args, **kwargs): # pragma: no cover - return SmartEmphasisExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return SmartEmphasisExtension(**kwargs) diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py index 6add986..35c78a8 100644 --- a/markdown/extensions/smarty.py +++ b/markdown/extensions/smarty.py @@ -168,7 +168,7 @@ class SubstituteTextPattern(HtmlPattern): class SmartyExtension(Extension): - def __init__(self, *args, **kwargs): + def __init__(self, **kwargs): self.config = { 'smart_quotes': [True, 'Educate quotes'], 'smart_angled_quotes': [False, 'Educate angled quotes'], @@ -176,7 +176,7 @@ class SmartyExtension(Extension): 'smart_ellipses': [True, 'Educate ellipses'], 'substitutions': [{}, 'Overwrite default substitutions'], } - super(SmartyExtension, self).__init__(*args, **kwargs) + super(SmartyExtension, self).__init__(**kwargs) self.substitutions = dict(substitutions) self.substitutions.update(self.getConfig('substitutions', default={})) @@ -264,5 +264,5 @@ class SmartyExtension(Extension): md.ESCAPED_CHARS.extend(['"', "'"]) -def makeExtension(*args, **kwargs): # pragma: no cover - return SmartyExtension(*args, **kwargs) +def makeExtension(**kwargs): # pragma: no cover + return SmartyExtension(**kwargs) diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index dc459f3..a48660b 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -223,5 +223,5 @@ class TableExtension(Extension): '