Skip to content

Commit

Permalink
refactor: add proper top-level __all__ specifiers (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 authored Aug 12, 2024
1 parent 17282d8 commit e11fc86
Show file tree
Hide file tree
Showing 19 changed files with 756 additions and 39 deletions.
541 changes: 532 additions & 9 deletions falcon/__init__.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions falcon/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@
from .structures import SSEvent
from .ws import WebSocket
from .ws import WebSocketOptions

__all__ = (
'App',
'BoundedStream',
'Request',
'Response',
'SSEvent',
'WebSocket',
'WebSocketOptions',
)
2 changes: 1 addition & 1 deletion falcon/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from .ws import WebSocket
from .ws import WebSocketOptions

__all__ = ['App']
__all__ = ('App',)


# TODO(vytas): Clean up these foul workarounds before the 4.0 release.
Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from . import _request_helpers as asgi_helpers
from .stream import BoundedStream

__all__ = ['Request']
__all__ = ('Request',)

_SINGLETON_HEADERS_BYTESTR = frozenset([h.encode() for h in SINGLETON_HEADERS])

Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from falcon.util.misc import _encode_items_to_latin1
from falcon.util.misc import is_python_func

__all__ = ['Response']
__all__ = ('Response',)


class Response(response.Response):
Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from falcon.errors import OperationNotAllowed

__all__ = ['BoundedStream']
__all__ = ('BoundedStream',)


class BoundedStream:
Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/structures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from falcon.constants import MEDIA_JSON
from falcon.media.json import _DEFAULT_JSON_HANDLER

__all__ = ['SSEvent']
__all__ = ('SSEvent',)


class SSEvent:
Expand Down
2 changes: 1 addition & 1 deletion falcon/asgi/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
_WebSocketState = Enum('_WebSocketState', 'HANDSHAKE ACCEPTED CLOSED')


__all__ = ['WebSocket']
__all__ = ('WebSocket',)


class WebSocket:
Expand Down
2 changes: 1 addition & 1 deletion falcon/bench/nuts/nuts/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pecan import set_config
from pecan.testing import load_test_app

__all__ = ['FunctionalTest']
__all__ = ('FunctionalTest',)


class FunctionalTest(TestCase):
Expand Down
22 changes: 22 additions & 0 deletions falcon/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
import os
import sys

__all__ = (
'HTTP_METHODS',
'WEBDAV_METHODS',
'COMBINED_METHODS',
'DEFAULT_MEDIA_TYPE',
'MEDIA_BMP',
'MEDIA_GIF',
'MEDIA_HTML',
'MEDIA_JPEG',
'MEDIA_JS',
'MEDIA_JSON',
'MEDIA_MSGPACK',
'MEDIA_MULTIPART',
'MEDIA_PNG',
'MEDIA_TEXT',
'MEDIA_URLENCODED',
'MEDIA_XML',
'MEDIA_YAML',
'SINGLETON_HEADERS',
'WebSocketPayloadType',
)

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

Expand Down
4 changes: 2 additions & 2 deletions falcon/media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .multipart import MultipartFormHandler
from .urlencoded import URLEncodedFormHandler

__all__ = [
__all__ = (
'BaseHandler',
'BinaryBaseHandlerWS',
'TextBaseHandlerWS',
Expand All @@ -22,4 +22,4 @@
'MissingDependencyHandler',
'MultipartFormHandler',
'URLEncodedFormHandler',
]
)
2 changes: 1 addition & 1 deletion falcon/media/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _raise(self, *args, **kwargs):
class Handlers(UserDict):
"""A :class:`dict`-like object that manages Internet media type handlers."""

def __init__(self, initial=None):
def __init__(self, initial=None) -> None:
self._resolve = self._create_resolver()

handlers: Mapping[str, BaseHandler] = initial or {
Expand Down
2 changes: 1 addition & 1 deletion falcon/routing/compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def __setattr__(self, name, value) -> None:


class _CxParent:
def __init__(self):
def __init__(self) -> None:
self._children: List[_CxElement] = []

def append_child(self, construct: _CxElement):
Expand Down
164 changes: 164 additions & 0 deletions falcon/status_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,167 @@
HTTP_792 = '792 Climate change driven catastrophic weather event'
HTTP_797 = '797 This is the last page of the Internet. Go back'
HTTP_799 = '799 End of the world'

__all__ = (
'HTTP_100',
'HTTP_101',
'HTTP_102',
'HTTP_200',
'HTTP_201',
'HTTP_202',
'HTTP_203',
'HTTP_204',
'HTTP_205',
'HTTP_206',
'HTTP_207',
'HTTP_208',
'HTTP_226',
'HTTP_300',
'HTTP_301',
'HTTP_302',
'HTTP_303',
'HTTP_304',
'HTTP_305',
'HTTP_307',
'HTTP_308',
'HTTP_400',
'HTTP_401',
'HTTP_402',
'HTTP_403',
'HTTP_404',
'HTTP_405',
'HTTP_406',
'HTTP_407',
'HTTP_408',
'HTTP_409',
'HTTP_410',
'HTTP_411',
'HTTP_412',
'HTTP_413',
'HTTP_414',
'HTTP_415',
'HTTP_416',
'HTTP_417',
'HTTP_418',
'HTTP_422',
'HTTP_423',
'HTTP_424',
'HTTP_426',
'HTTP_428',
'HTTP_429',
'HTTP_431',
'HTTP_451',
'HTTP_500',
'HTTP_501',
'HTTP_502',
'HTTP_503',
'HTTP_504',
'HTTP_505',
'HTTP_507',
'HTTP_508',
'HTTP_511',
'HTTP_701',
'HTTP_702',
'HTTP_703',
'HTTP_710',
'HTTP_711',
'HTTP_712',
'HTTP_719',
'HTTP_720',
'HTTP_721',
'HTTP_722',
'HTTP_723',
'HTTP_724',
'HTTP_725',
'HTTP_726',
'HTTP_727',
'HTTP_740',
'HTTP_741',
'HTTP_742',
'HTTP_743',
'HTTP_744',
'HTTP_745',
'HTTP_748',
'HTTP_749',
'HTTP_750',
'HTTP_753',
'HTTP_754',
'HTTP_755',
'HTTP_759',
'HTTP_771',
'HTTP_772',
'HTTP_773',
'HTTP_774',
'HTTP_776',
'HTTP_777',
'HTTP_778',
'HTTP_779',
'HTTP_780',
'HTTP_781',
'HTTP_782',
'HTTP_783',
'HTTP_784',
'HTTP_785',
'HTTP_786',
'HTTP_791',
'HTTP_792',
'HTTP_797',
'HTTP_799',
'HTTP_ACCEPTED',
'HTTP_ALREADY_REPORTED',
'HTTP_BAD_GATEWAY',
'HTTP_BAD_REQUEST',
'HTTP_CONFLICT',
'HTTP_CONTINUE',
'HTTP_CREATED',
'HTTP_EXPECTATION_FAILED',
'HTTP_FAILED_DEPENDENCY',
'HTTP_FORBIDDEN',
'HTTP_FOUND',
'HTTP_GATEWAY_TIMEOUT',
'HTTP_GONE',
'HTTP_HTTP_VERSION_NOT_SUPPORTED',
'HTTP_IM_A_TEAPOT',
'HTTP_IM_USED',
'HTTP_INSUFFICIENT_STORAGE',
'HTTP_INTERNAL_SERVER_ERROR',
'HTTP_LENGTH_REQUIRED',
'HTTP_LOCKED',
'HTTP_LOOP_DETECTED',
'HTTP_METHOD_NOT_ALLOWED',
'HTTP_MOVED_PERMANENTLY',
'HTTP_MULTIPLE_CHOICES',
'HTTP_MULTI_STATUS',
'HTTP_NETWORK_AUTHENTICATION_REQUIRED',
'HTTP_NON_AUTHORITATIVE_INFORMATION',
'HTTP_NOT_ACCEPTABLE',
'HTTP_NOT_FOUND',
'HTTP_NOT_IMPLEMENTED',
'HTTP_NOT_MODIFIED',
'HTTP_NO_CONTENT',
'HTTP_OK',
'HTTP_PARTIAL_CONTENT',
'HTTP_PAYMENT_REQUIRED',
'HTTP_PERMANENT_REDIRECT',
'HTTP_PRECONDITION_FAILED',
'HTTP_PRECONDITION_REQUIRED',
'HTTP_PROCESSING',
'HTTP_PROXY_AUTHENTICATION_REQUIRED',
'HTTP_REQUESTED_RANGE_NOT_SATISFIABLE',
'HTTP_REQUEST_ENTITY_TOO_LARGE',
'HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE',
'HTTP_REQUEST_TIMEOUT',
'HTTP_REQUEST_URI_TOO_LONG',
'HTTP_RESET_CONTENT',
'HTTP_SEE_OTHER',
'HTTP_SERVICE_UNAVAILABLE',
'HTTP_SWITCHING_PROTOCOLS',
'HTTP_TEMPORARY_REDIRECT',
'HTTP_TOO_MANY_REQUESTS',
'HTTP_UNAUTHORIZED',
'HTTP_UNAVAILABLE_FOR_LEGAL_REASONS',
'HTTP_UNPROCESSABLE_ENTITY',
'HTTP_UNSUPPORTED_MEDIA_TYPE',
'HTTP_UPGRADE_REQUIRED',
'HTTP_USE_PROXY',
)
2 changes: 1 addition & 1 deletion falcon/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io
from typing import BinaryIO, Callable, List, Optional, TypeVar, Union

__all__ = ['BoundedStream']
__all__ = ('BoundedStream',)


Result = TypeVar('Result', bound=Union[bytes, List[bytes]])
Expand Down
5 changes: 2 additions & 3 deletions falcon/util/mediatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import typing

__all__ = ('parse_header',)


def _parse_param_old_stdlib(s): # type: ignore
while s[:1] == ';':
Expand Down Expand Up @@ -84,6 +86,3 @@ def parse_header(line: str) -> typing.Tuple[str, dict]:
return (key.strip(), pdict)

return _parse_header_old_stdlib(line)


__all__ = ['parse_header']
4 changes: 2 additions & 2 deletions falcon/util/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

from falcon.util import deprecated

__all__ = [
__all__ = (
'async_to_sync',
'create_task',
'get_running_loop',
'runs_sync',
'sync_to_async',
'wrap_sync_to_async',
'wrap_sync_to_async_unsafe',
]
)

Result = TypeVar('Result')

Expand Down
2 changes: 1 addition & 1 deletion falcon/util/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import datetime
from typing import Optional

__all__ = ['TimezoneGMT']
__all__ = ('TimezoneGMT',)


class TimezoneGMT(datetime.tzinfo):
Expand Down
23 changes: 11 additions & 12 deletions falcon/util/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
_cy_uri = None


__all__ = (
'decode',
'encode',
'encode_value',
'encode_check_escaped',
'encode_value_check_escaped',
'parse_host',
'parse_query_string',
'unquote_string',
)

# NOTE(kgriffs): See also RFC 3986
_UNRESERVED = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'

Expand Down Expand Up @@ -547,15 +558,3 @@ def unquote_string(quoted: str) -> str:
if _cy_uri is not None:
decode = _cy_uri.decode # NOQA
parse_query_string = _cy_uri.parse_query_string # NOQA


__all__ = [
'decode',
'encode',
'encode_value',
'encode_check_escaped',
'encode_value_check_escaped',
'parse_host',
'parse_query_string',
'unquote_string',
]

0 comments on commit e11fc86

Please sign in to comment.