diff options
author | Justin Mayer <entroP@gmail.com> | 2021-08-18 14:24:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 14:24:39 +0200 |
commit | f438a4b6eab6714d1738c16e1c19a027768d3b16 (patch) | |
tree | 9ae1fde326526fbaa8c55f1e8b61c149c1314ea7 | |
parent | 5e9e1af94ef810336360ff83872f36ae61465dbc (diff) | |
parent | f9fb0f980645550459e651f672a132d47a76f8da (diff) | |
download | feedgenerator-f438a4b6eab6714d1738c16e1c19a027768d3b16.tar.gz |
Merge pull request #29 from getpelican/modernize
Update code for Python 3.6+
-rw-r--r-- | .pre-commit-config.yaml | 21 | ||||
-rw-r--r-- | feedgenerator/django/utils/encoding.py | 2 | ||||
-rw-r--r-- | feedgenerator/django/utils/feedgenerator.py | 8 | ||||
-rw-r--r-- | feedgenerator/django/utils/functional.py | 6 | ||||
-rw-r--r-- | feedgenerator/django/utils/timezone.py | 2 | ||||
-rw-r--r-- | feedgenerator/django/utils/xmlutils.py | 4 | ||||
-rw-r--r-- | setup.py | 1 |
7 files changed, 32 insertions, 12 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..049ecc2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-merge-conflict + - id: check-toml + - id: debug-statements + - id: detect-private-key + - id: end-of-file-fixer + - id: forbid-new-submodules + - id: trailing-whitespace + + - repo: https://github.com/asottile/pyupgrade + rev: v2.23.3 + hooks: + - id: pyupgrade + args: [--py36-plus] diff --git a/feedgenerator/django/utils/encoding.py b/feedgenerator/django/utils/encoding.py index ce8334e..02bb65c 100644 --- a/feedgenerator/django/utils/encoding.py +++ b/feedgenerator/django/utils/encoding.py @@ -13,7 +13,7 @@ class DjangoUnicodeDecodeError(UnicodeDecodeError): def __str__(self): original = UnicodeDecodeError.__str__(self) - return '%s. You passed in %r (%s)' % (original, self.obj, + return '{}. You passed in {!r} ({})'.format(original, self.obj, type(self.obj)) def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'): diff --git a/feedgenerator/django/utils/feedgenerator.py b/feedgenerator/django/utils/feedgenerator.py index bf33848..b5d858c 100644 --- a/feedgenerator/django/utils/feedgenerator.py +++ b/feedgenerator/django/utils/feedgenerator.py @@ -39,7 +39,7 @@ def rfc2822_date(date): # We do this ourselves to be timezone aware, email.Utils is not tz aware. dow = days[date.weekday()] month = months[date.month - 1] - time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month)) + time_str = date.strftime(f'{dow}, %d {month} %Y %H:%M:%S ') if is_aware(date): offset = date.tzinfo.utcoffset(date) timezone = (offset.days * 24 * 60) + (offset.seconds // 60) @@ -73,9 +73,9 @@ def get_tag_uri(url, date): fragment = '' if bits.fragment != '': fragment = '/%s' % (bits.fragment) - return 'tag:%s%s:%s%s' % (bits.hostname, d, bits.path, fragment) + return f'tag:{bits.hostname}{d}:{bits.path}{fragment}' -class SyndicationFeed(object): +class SyndicationFeed: "Base class for all syndication feeds. Subclasses should provide write()" def __init__(self, title, link, description, language=None, author_email=None, author_name=None, author_link=None, subtitle=None, categories=None, @@ -196,7 +196,7 @@ class SyndicationFeed(object): else: return datetime.datetime.now() -class Enclosure(object): +class Enclosure: "Represents an RSS enclosure" def __init__(self, url, length, mime_type): "All args are expected to be Python Unicode objects" diff --git a/feedgenerator/django/utils/functional.py b/feedgenerator/django/utils/functional.py index ba4d586..af31971 100644 --- a/feedgenerator/django/utils/functional.py +++ b/feedgenerator/django/utils/functional.py @@ -29,7 +29,7 @@ def memoize(func, cache, num_args): return result return wrapper -class cached_property(object): +class cached_property: """ Decorator that creates converts a method with a single self argument into a property cached on the instance. @@ -41,7 +41,7 @@ class cached_property(object): res = instance.__dict__[self.func.__name__] = self.func(instance) return res -class Promise(object): +class Promise: """ This is just a base class for the proxy class created in the closure of the lazy function. It can be used to recognize @@ -192,7 +192,7 @@ def new_method_proxy(func): return func(self._wrapped, *args) return inner -class LazyObject(object): +class LazyObject: """ A wrapper for another class that can be used to delay instantiation of the wrapped class. diff --git a/feedgenerator/django/utils/timezone.py b/feedgenerator/django/utils/timezone.py index 3ad8517..38a9a10 100644 --- a/feedgenerator/django/utils/timezone.py +++ b/feedgenerator/django/utils/timezone.py @@ -173,7 +173,7 @@ def deactivate(): if hasattr(_active, "value"): del _active.value -class override(object): +class override: """ Temporarily set the time zone for the current thread. diff --git a/feedgenerator/django/utils/xmlutils.py b/feedgenerator/django/utils/xmlutils.py index d234708..9bec3dd 100644 --- a/feedgenerator/django/utils/xmlutils.py +++ b/feedgenerator/django/utils/xmlutils.py @@ -17,5 +17,5 @@ class SimplerXMLGenerator(XMLGenerator): self._write('<' + name) # sort attributes for consistent output for (name, value) in sorted(attrs.items()): - self._write(' %s=%s' % (name, quoteattr(value))) - self._write(str('>')) + self._write(f' {name}={quoteattr(value)}') + self._write('>') @@ -1,6 +1,5 @@ #!/usr/bin/env python -from io import open # Using setuptools rather than distutils to get the `develop` command from setuptools import setup |