From 3863b6304aff70a39b106e1b96f61bf773ae15c3 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Sat, 2 Jul 2022 21:13:38 +0000 Subject: [PATCH] chore: update codebase for modern python We're on Python 3.7 and higher, so we can clean up any artifacts left from previously-supported Python eras. Most of the heavy lifting was done with `pyupgrade` followed by unused improts removal (thanks to `flake8` check) Refs: https://pypi.org/project/pyupgrade/ Closes #203 Signed-off-by: Mike Fiedler --- readme_renderer/__about__.py | 1 - readme_renderer/__init__.py | 1 - readme_renderer/__main__.py | 1 - readme_renderer/clean.py | 1 - readme_renderer/markdown.py | 3 +-- readme_renderer/rst.py | 3 +-- readme_renderer/txt.py | 10 +--------- setup.py | 1 - tests/test_markdown.py | 5 ++--- tests/test_rst.py | 4 ++-- tests/test_txt.py | 5 ++--- 11 files changed, 9 insertions(+), 26 deletions(-) diff --git a/readme_renderer/__about__.py b/readme_renderer/__about__.py index b1e67d4..3c2e86e 100644 --- a/readme_renderer/__about__.py +++ b/readme_renderer/__about__.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function __all__ = [ "__title__", diff --git a/readme_renderer/__init__.py b/readme_renderer/__init__.py index c3eb860..cdec169 100644 --- a/readme_renderer/__init__.py +++ b/readme_renderer/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function diff --git a/readme_renderer/__main__.py b/readme_renderer/__main__.py index 527d96d..74983fc 100644 --- a/readme_renderer/__main__.py +++ b/readme_renderer/__main__.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, print_function import argparse from readme_renderer.rst import render import sys diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py index 332dd5b..5790a36 100644 --- a/readme_renderer/clean.py +++ b/readme_renderer/clean.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function import functools from typing import Any, Dict, Iterator, List, Optional diff --git a/readme_renderer/markdown.py b/readme_renderer/markdown.py index d5d3ccb..85dcd3b 100644 --- a/readme_renderer/markdown.py +++ b/readme_renderer/markdown.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function import re import warnings @@ -117,7 +116,7 @@ def replacer(match: Match[Any]) -> str: highlighted = pygments.highlight(code, lexer, formatter) - return '
{}
'.format(highlighted) + return f'
{highlighted}
' result = code_expr.sub(replacer, html) diff --git a/readme_renderer/rst.py b/readme_renderer/rst.py index 7bfaebc..cadd843 100644 --- a/readme_renderer/rst.py +++ b/readme_renderer/rst.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function import io from typing import Any, Dict, IO, Optional, Union @@ -43,7 +42,7 @@ def emptytag( if "height" in node: attributes["height"] = node["height"] - return super(ReadMeHTMLTranslator, self).emptytag( + return super().emptytag( node, tagname, suffix, **attributes ) diff --git a/readme_renderer/txt.py b/readme_renderer/txt.py index 13dc38a..5af4805 100644 --- a/readme_renderer/txt.py +++ b/readme_renderer/txt.py @@ -11,20 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function -import sys from typing import Any, Optional from .clean import clean -if sys.version_info >= (3,): - from html import escape as html_escape -else: - from cgi import escape - - def html_escape(s): - return escape(s, quote=True).replace("'", ''') +from html import escape as html_escape def render(raw: str, **kwargs: Any) -> Optional[str]: diff --git a/setup.py b/setup.py index ec2e685..00e62e7 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import, division, print_function import os diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 492bc81..f886480 100755 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -1,4 +1,3 @@ -import io import glob import os @@ -26,11 +25,11 @@ ) def test_md_fixtures(md_filename, html_filename, variant): # Get our Markup - with io.open(md_filename, encoding='utf-8') as f: + with open(md_filename, encoding='utf-8') as f: md_markup = f.read() # Get our expected - with io.open(html_filename, encoding="utf-8") as f: + with open(html_filename, encoding="utf-8") as f: expected = f.read() assert render(md_markup, variant=variant) == expected diff --git a/tests/test_rst.py b/tests/test_rst.py index 4e04c17..5ffeae6 100755 --- a/tests/test_rst.py +++ b/tests/test_rst.py @@ -18,11 +18,11 @@ ) def test_rst_fixtures(rst_filename, html_filename): # Get our Markup - with io.open(rst_filename, encoding='utf-8') as f: + with open(rst_filename, encoding='utf-8') as f: rst_markup = f.read() # Get our expected - with io.open(html_filename, encoding="utf-8") as f: + with open(html_filename, encoding="utf-8") as f: expected = f.read() out = render(rst_markup) diff --git a/tests/test_txt.py b/tests/test_txt.py index b3a5274..d147c3b 100644 --- a/tests/test_txt.py +++ b/tests/test_txt.py @@ -1,4 +1,3 @@ -import io import glob import os.path @@ -18,11 +17,11 @@ ) def test_txt_fixtures(txt_filename, html_filename): # Get our Markup - with io.open(txt_filename, encoding='utf-8') as f: + with open(txt_filename, encoding='utf-8') as f: txt_markup = f.read() # Get our expected - with io.open(html_filename, encoding="utf-8") as f: + with open(html_filename, encoding="utf-8") as f: expected = f.read() out = render(txt_markup)