diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1c9a59..8866812 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,3 +18,9 @@ repos: rev: 3.8.3 hooks: - id: flake8 + + - repo: https://github.com/asottile/pyupgrade + rev: v2.4.1 + hooks: + - id: pyupgrade + args: [--py36-plus] diff --git a/setup.py b/setup.py index a3bcb27..d51ebda 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import codecs import os diff --git a/src/flask_uploads/extensions.py b/src/flask_uploads/extensions.py index 52e0067..8e0f67b 100644 --- a/src/flask_uploads/extensions.py +++ b/src/flask_uploads/extensions.py @@ -1,4 +1,3 @@ - """Extension presets and extension configuration.""" import os @@ -63,7 +62,7 @@ DEFAULTS = TEXT + DOCUMENTS + IMAGES + DATA -class All(object): +class All: """ This type can be used to allow all extensions. There is a predefined instance named `ALL`. @@ -77,7 +76,7 @@ def __contains__(self, item): ALL = All() -class AllExcept(object): +class AllExcept: """ This can be used to allow all file types except certain ones. For example, to ban .exe and .iso files, pass:: diff --git a/src/flask_uploads/flask_uploads.py b/src/flask_uploads/flask_uploads.py index 52730fc..492c049 100644 --- a/src/flask_uploads/flask_uploads.py +++ b/src/flask_uploads/flask_uploads.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ flaskext.uploads ================ @@ -106,7 +105,7 @@ def configure_uploads(app, upload_sets): app.register_blueprint(uploads_mod) -class UploadConfiguration(object): +class UploadConfiguration: """ This holds the configuration for a single `UploadSet`. The constructor's arguments are also the attributes. @@ -134,7 +133,7 @@ def __eq__(self, other): return self.tuple == other.tuple -class UploadSet(object): +class UploadSet: """ This represents a single set of uploaded files. Each upload set is independent of the others. This can be reused across multiple application diff --git a/src/flask_uploads/test_helper.py b/src/flask_uploads/test_helper.py index 6ce7781..c9eb657 100644 --- a/src/flask_uploads/test_helper.py +++ b/src/flask_uploads/test_helper.py @@ -5,15 +5,8 @@ - it has to be importable - it can't be moved in the tests directory """ -import sys - from werkzeug.datastructures import FileStorage -if sys.version_info < (3,): # python 2 - string_types = basestring, # noqa: F821 -else: # python 3 - string_types = str, - class TestingFileStorage(FileStorage): """ @@ -51,7 +44,7 @@ def save(self, dst, buffer_size=16384): :param dst: The file to save to. :param buffer_size: Ignored. """ - if isinstance(dst, string_types): + if isinstance(dst, str): self.saved = dst else: self.saved = dst.name diff --git a/tests/test_flask_reuploaded.py b/tests/test_flask_reuploaded.py index 3a29d0d..86da299 100644 --- a/tests/test_flask_reuploaded.py +++ b/tests/test_flask_reuploaded.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- """ :copyright: 2010 Matthew "LeafStorm" Frazier :license: MIT/X11, see LICENSE for details """ -from __future__ import with_statement import os import os.path @@ -22,7 +20,7 @@ from flask_uploads import lowercase_ext -class TestMiscellaneous(object): +class TestMiscellaneous: def test_tfs(self): tfs = TestingFileStorage(filename='foo.bar') assert tfs.filename == 'foo.bar' @@ -68,7 +66,7 @@ def test_custom_iterables(self): Config = UploadConfiguration -class TestConfiguration(object): +class TestConfiguration: def setup(self): self.app = Flask(__name__) @@ -157,7 +155,7 @@ def test_default_destination_callable(self): assert photo_conf == Config('/mnt/photos', 'http://localhost:6002/') -class TestPreconditions(object): +class TestPreconditions: def test_filenames(self): uset = UploadSet('files') uset._config = Config('/uploads') @@ -178,7 +176,7 @@ def test_default_extensions(self): assert uset.extension_allowed(ext) is result -class TestSaving(object): +class TestSaving: def setup(self): self.old_makedirs = os.makedirs os.makedirs = lambda v: None @@ -260,7 +258,7 @@ def test_storage_is_not_a_werkzeug_datastructure(self): uset.save(non_storage) -class TestConflictResolution(object): +class TestConflictResolution: def setup(self): self.extant_files = [] self.old_exists = os.path.exists @@ -311,7 +309,7 @@ def test_conflict_without_extension(self): assert res == 'foo_1' -class TestPathsAndURLs(object): +class TestPathsAndURLs: def test_path(self): uset = UploadSet('files') uset._config = Config('/uploads')