Skip to content

Commit

Permalink
style: enable isort in ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Jul 12, 2024
1 parent 35ce52c commit 18dff4a
Show file tree
Hide file tree
Showing 93 changed files with 195 additions and 222 deletions.
1 change: 0 additions & 1 deletion e2e-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import falcon.testing


HERE = pathlib.Path(__file__).resolve().parent
INDEX = '/static/index.html'

Expand Down
4 changes: 3 additions & 1 deletion e2e-tests/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import falcon
import falcon.asgi

from .chat import Chat
from .hub import Events, Hub
from .hub import Events
from .hub import Hub
from .ping import Pong

HERE = pathlib.Path(__file__).resolve().parent
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/server/chat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from falcon.asgi import Request, WebSocket
from falcon.asgi import Request
from falcon.asgi import WebSocket

from .hub import Hub

Expand Down
5 changes: 4 additions & 1 deletion e2e-tests/server/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import typing
import uuid

from falcon.asgi import Request, Response, SSEvent, WebSocket
from falcon.asgi import Request
from falcon.asgi import Response
from falcon.asgi import SSEvent
from falcon.asgi import WebSocket


class Emitter:
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/server/ping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from http import HTTPStatus

import falcon
from falcon.asgi import Request, Response
from falcon.asgi import Request
from falcon.asgi import Response


class Pong:
Expand Down
1 change: 0 additions & 1 deletion falcon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
from falcon.util import wrap_sync_to_async_unsafe
from falcon.version import __version__


# NOTE(kgriffs): Only to be used internally on the rare occasion that we
# need to log something that we can't communicate any other way.
_logger = _logging.getLogger('falcon')
Expand Down
5 changes: 3 additions & 2 deletions falcon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
from falcon.response import Response
from falcon.response import ResponseOptions
import falcon.status_codes as status
from falcon.typing import ErrorHandler, ErrorSerializer, SinkPrefix
from falcon.typing import ErrorHandler
from falcon.typing import ErrorSerializer
from falcon.typing import SinkPrefix
from falcon.util import deprecation
from falcon.util import misc
from falcon.util.misc import code_to_http_status


# PERF(vytas): On Python 3.5+ (including cythonized modules),
# reference via module global is faster than going via self
_BODILESS_STATUS_CODES = frozenset(
Expand Down
3 changes: 2 additions & 1 deletion falcon/app_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from falcon import util
from falcon.constants import MEDIA_JSON
from falcon.constants import MEDIA_XML
from falcon.errors import CompatibilityError, HTTPError
from falcon.errors import CompatibilityError
from falcon.errors import HTTPError
from falcon.request import Request
from falcon.response import Response
from falcon.util.sync import _wrap_non_coroutine_unsafe
Expand Down
3 changes: 2 additions & 1 deletion falcon/asgi/_asgi_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import functools
import inspect

from falcon.errors import UnsupportedError, UnsupportedScopeError
from falcon.errors import UnsupportedError
from falcon.errors import UnsupportedScopeError


@functools.lru_cache(maxsize=16)
Expand Down
5 changes: 3 additions & 2 deletions falcon/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
from falcon.http_status import HTTPStatus
from falcon.media.multipart import MultipartFormHandler
import falcon.routing
from falcon.typing import ErrorHandler, SinkPrefix
from falcon.typing import ErrorHandler
from falcon.typing import SinkPrefix
from falcon.util.misc import is_python_func
from falcon.util.sync import _should_wrap_non_coroutines
from falcon.util.sync import _wrap_non_coroutine_unsafe
from falcon.util.sync import get_running_loop
from falcon.util.sync import wrap_sync_to_async

from ._asgi_helpers import _validate_asgi_scope
from ._asgi_helpers import _wrap_asgi_coroutine_func
from .multipart import MultipartForm
Expand All @@ -50,7 +52,6 @@
from .ws import WebSocket
from .ws import WebSocketOptions


__all__ = ['App']


Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from falcon.constants import SINGLETON_HEADERS
from falcon.util.uri import parse_host
from falcon.util.uri import parse_query_string

from . import _request_helpers as asgi_helpers
from .stream import BoundedStream


__all__ = ['Request']

_SINGLETON_HEADERS_BYTESTR = frozenset([h.encode() for h in SINGLETON_HEADERS])
Expand Down
3 changes: 2 additions & 1 deletion falcon/asgi/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

from falcon import response
from falcon.constants import _UNSET
from falcon.util.misc import _encode_items_to_latin1, is_python_func
from falcon.util.misc import _encode_items_to_latin1
from falcon.util.misc import is_python_func

__all__ = ['Response']

Expand Down
1 change: 0 additions & 1 deletion falcon/asgi/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from falcon.errors import OperationNotAllowed


__all__ = ['BoundedStream']


Expand Down
1 change: 0 additions & 1 deletion falcon/asgi/structures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from falcon.constants import MEDIA_JSON
from falcon.media.json import _DEFAULT_JSON_HANDLER


__all__ = ['SSEvent']


Expand Down
21 changes: 11 additions & 10 deletions falcon/asgi/ws.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import asyncio
import collections
from enum import Enum
from typing import Any
from typing import Awaitable
from typing import Callable
from typing import Deque
from typing import Dict
from typing import Iterable
from typing import Mapping
from typing import Optional
from typing import Union
from typing import (
Any,
Awaitable,
Callable,
Deque,
Dict,
Iterable,
Mapping,
Optional,
Union,
)

import falcon
from falcon import errors
Expand All @@ -18,7 +20,6 @@
from falcon.asgi_spec import WSCloseCode
from falcon.constants import WebSocketPayloadType


_WebSocketState = Enum('_WebSocketState', 'HANDSHAKE ACCEPTED CLOSED')


Expand Down
3 changes: 2 additions & 1 deletion falcon/bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# limitations under the License.

import argparse
from collections import defaultdict, deque
from collections import defaultdict
from collections import deque
from decimal import Decimal
import gc
import inspect
Expand Down
3 changes: 2 additions & 1 deletion falcon/bench/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def hello(account_id):


def werkzeug(body, headers):
from werkzeug.routing import Map
from werkzeug.routing import Rule
import werkzeug.wrappers as werkzeug
from werkzeug.routing import Map, Rule

path = '/hello/<account_id>/test'
url_map = Map([Rule(path, endpoint='hello')])
Expand Down
1 change: 0 additions & 1 deletion falcon/bench/dj/dj/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.urls import re_path as url
from hello import views


urlpatterns = [url(r'^hello/(?P<account_id>[0-9]+)/test$', views.hello)]
1 change: 0 additions & 1 deletion falcon/bench/dj/hello/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import django
from django.http import HttpResponse


_body = django.x_test_body
_headers = django.x_test_headers

Expand Down
1 change: 0 additions & 1 deletion falcon/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import sys


PYPY = sys.implementation.name == 'pypy'
"""Evaluates to ``True`` when the current Python implementation is PyPy."""

Expand Down
1 change: 0 additions & 1 deletion falcon/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def on_get(self, req, resp):
from falcon.util.deprecation import deprecated_args
from falcon.util.misc import dt_to_http


__all__ = (
'CompatibilityError',
'DelimiterError',
Expand Down
1 change: 0 additions & 1 deletion falcon/forwarded.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from falcon.util.uri import unquote_string


# '-' at the end to prevent interpretation as range in a char class
_TCHAR = string.digits + string.ascii_letters + r"!#$%&'*+.^_`|~-"

Expand Down
1 change: 0 additions & 1 deletion falcon/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from falcon.util.misc import get_argnames
from falcon.util.sync import _wrap_non_coroutine_unsafe


_DECORABLE_METHOD_NAME = re.compile(
r'^on_({})(_\w+)?$'.format('|'.join(method.lower() for method in COMBINED_METHODS))
)
Expand Down
4 changes: 3 additions & 1 deletion falcon/http_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import xml.etree.ElementTree as et

from falcon.constants import MEDIA_JSON
from falcon.util import code_to_http_status, http_status_to_code, uri
from falcon.util import code_to_http_status
from falcon.util import http_status_to_code
from falcon.util import uri
from falcon.util.deprecation import deprecated_args


Expand Down
8 changes: 2 additions & 6 deletions falcon/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

from functools import partial
import inspect
from typing import Callable # NOQA: F401
from typing import Dict # NOQA: F401
from typing import List
from typing import Optional
from typing import Type # NOQA: F401
from typing import Callable, Dict, List, Optional, Type

from falcon import app_helpers
from falcon.app import App
Expand Down Expand Up @@ -101,7 +97,7 @@ def wraps(fn):


# router inspection registry
_supported_routers = {} # type: Dict[Type, Callable]
_supported_routers: Dict[Type, Callable] = {}


def inspect_static_routes(app: App) -> 'List[StaticRouteInfo]':
Expand Down
1 change: 0 additions & 1 deletion falcon/media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .multipart import MultipartFormHandler
from .urlencoded import URLEncodedFormHandler


__all__ = [
'BaseHandler',
'BinaryBaseHandlerWS',
Expand Down
1 change: 0 additions & 1 deletion falcon/media/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from falcon.util import misc
from falcon.util.mediatypes import parse_header


# TODO(vytas):
# * Better support for form-wide charset setting
# * Clean up, simplify, and optimize BufferedReader
Expand Down
4 changes: 1 addition & 3 deletions falcon/middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import Iterable
from typing import Optional
from typing import Union
from typing import Iterable, Optional, Union

from .request import Request
from .response import Response
Expand Down
4 changes: 2 additions & 2 deletions falcon/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
from falcon.util import http_status_to_code
from falcon.util import structures
from falcon.util import TimezoneGMT
from falcon.util.deprecation import AttributeRemovedError, deprecated
from falcon.util.deprecation import AttributeRemovedError
from falcon.util.deprecation import deprecated
from falcon.util.uri import encode_check_escaped as uri_encode
from falcon.util.uri import encode_value_check_escaped as uri_encode_value


GMT_TIMEZONE = TimezoneGMT()

_STREAM_LEN_REMOVED_MSG = (
Expand Down
5 changes: 1 addition & 4 deletions falcon/testing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import inspect
import json as json_module
import time
from typing import Dict
from typing import Optional
from typing import Sequence
from typing import Union
from typing import Dict, Optional, Sequence, Union
import warnings
import wsgiref.validate

Expand Down
6 changes: 1 addition & 5 deletions falcon/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
import socket
import sys
import time
from typing import Any
from typing import Dict
from typing import Iterable
from typing import Optional
from typing import Union
from typing import Any, Dict, Iterable, Optional, Union

import falcon
from falcon import errors as falcon_errors
Expand Down
1 change: 0 additions & 1 deletion falcon/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from falcon.request import Request
from falcon.response import Response


# Error handlers
ErrorHandler = Callable[[Request, Response, BaseException, dict], Any]

Expand Down
3 changes: 1 addition & 2 deletions falcon/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from falcon.util.sync import wrap_sync_to_async_unsafe
from falcon.util.time import TimezoneGMT


# NOTE(kgriffs): Backport support for the new 'SameSite' attribute
# for Python versions prior to 3.8. We do it this way because
# SimpleCookie does not give us a simple way to specify our own
Expand Down Expand Up @@ -81,8 +80,8 @@

def __getattr__(name: str) -> ModuleType:
if name == 'json':
import warnings
import json # NOQA
import warnings

warnings.warn(
'Importing json from "falcon.util" is deprecated.', DeprecatedWarning
Expand Down
5 changes: 1 addition & 4 deletions falcon/util/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
"""

import functools
from typing import Any
from typing import Callable
from typing import Optional
from typing import Any, Callable, Optional
import warnings


__all__ = (
'AttributeRemovedError',
'DeprecatedWarning',
Expand Down
Loading

0 comments on commit 18dff4a

Please sign in to comment.