Skip to content

Commit

Permalink
chore: update codebase for modern python
Browse files Browse the repository at this point in the history
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 pypa#203

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Jul 6, 2022
1 parent 209bcae commit b92c64f
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 26 deletions.
1 change: 0 additions & 1 deletion readme_renderer/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
1 change: 0 additions & 1 deletion readme_renderer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion readme_renderer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function
import argparse
from readme_renderer.rst import render
import sys
Expand Down
1 change: 0 additions & 1 deletion readme_renderer/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions readme_renderer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,7 +116,7 @@ def replacer(match: Match[Any]) -> str:

highlighted = pygments.highlight(code, lexer, formatter)

return '<pre>{}</pre>'.format(highlighted)
return f'<pre>{highlighted}</pre>'

result = code_expr.sub(replacer, html)

Expand Down
3 changes: 1 addition & 2 deletions readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
10 changes: 1 addition & 9 deletions readme_renderer/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("'", '&#x27;')
from html import escape as html_escape


def render(raw: str, **kwargs: Any) -> Optional[str]:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import glob
import os

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_txt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import glob
import os.path

Expand All @@ -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)
Expand Down

0 comments on commit b92c64f

Please sign in to comment.