Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix lint #1157

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"invoke",
# lint
"black",
"ruff==0.0.278", # Ruff is moving really fast, so pinning for now.
"ruff==0.0.278", # Ruff is moving really fast, so pinning for now.
"toml",
"flake8",
"flake8-pyproject",
Expand All @@ -32,9 +32,11 @@ publish = "invoke publish {args}"
docs = "invoke docs {args}"
check = ["lint-py", "lint-js", "test-py", "test-js", "test-docs"]

lint = ["lint-py", "lint-js"]
lint-py = "invoke lint-py {args}"
lint-js = "invoke lint-js {args}"

test = ["test-py", "test-js", "test-docs"]
test-py = "invoke test-py {args}"
test-js = "invoke test-js"
test-docs = "invoke test-docs"
Expand All @@ -56,7 +58,7 @@ warn_unused_ignores = true
# --- Flake8 ---------------------------------------------------------------------------

[tool.flake8]
select = ["RPY"] # only need to check with reactpy-flake8
select = ["RPY"] # only need to check with reactpy-flake8
exclude = ["**/node_modules/*", ".eggs/*", ".tox/*", "**/venv/*"]

# --- Ruff -----------------------------------------------------------------------------
Expand Down Expand Up @@ -95,27 +97,37 @@ select = [
]
ignore = [
# TODO: turn this on later
"N802", "N806", # allow TitleCase functions/variables
"N802",
"N806", # allow TitleCase functions/variables
# We're not any cryptography
"S311",
# For loop variable re-assignment seems like an uncommon mistake
"PLW2901",
# Let Black deal with line-length
"E501",
# Allow args/attrs to shadow built-ins
"A002", "A003",
"A002",
"A003",
# Allow unused args (useful for documenting what the parameter is for later)
"ARG001", "ARG002", "ARG005",
"ARG001",
"ARG002",
"ARG005",
# Allow non-abstract empty methods in abstract base classes
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# If we're making an explicit comparison to a falsy value it was probably intentional
"PLC1901",
# Ignore checks for possible passwords
"S105", "S106", "S107",
"S105",
"S106",
"S107",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
"C901",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
]
unfixable = [
# Don't touch unused imports
Expand Down
22 changes: 13 additions & 9 deletions src/py/reactpy/reactpy/backend/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class Options(CommonOptions):

# BackendType.configure
def configure(
app: Sanic, component: RootComponentConstructor, options: Options | None = None
app: Sanic[Any, Any],
component: RootComponentConstructor,
options: Options | None = None,
) -> None:
"""Configure an application instance to display the given component"""
options = options or Options()
Expand All @@ -63,7 +65,7 @@ def configure(


# BackendType.create_development_app
def create_development_app() -> Sanic:
def create_development_app() -> Sanic[Any, Any]:
"""Return a :class:`Sanic` app instance in test mode"""
Sanic.test_mode = True
logger.warning("Sanic.test_mode is now active")
Expand All @@ -72,7 +74,7 @@ def create_development_app() -> Sanic:

# BackendType.serve_development_app
async def serve_development_app(
app: Sanic,
app: Sanic[Any, Any],
host: str,
port: int,
started: asyncio.Event | None = None,
Expand All @@ -81,7 +83,7 @@ async def serve_development_app(
await serve_with_uvicorn(app, host, port, started)


def use_request() -> request.Request:
def use_request() -> request.Request[Any, Any]:
"""Get the current ``Request``"""
return use_connection().carrier.request

Expand Down Expand Up @@ -113,7 +115,7 @@ def _setup_common_routes(
index_html = read_client_index_html(options)

async def single_page_app_files(
request: request.Request,
request: request.Request[Any, Any],
_: str = "",
) -> response.HTTPResponse:
return response.html(index_html)
Expand All @@ -131,7 +133,7 @@ async def single_page_app_files(
)

async def asset_files(
request: request.Request,
request: request.Request[Any, Any],
path: str = "",
) -> response.HTTPResponse:
path = urllib_parse.unquote(path)
Expand All @@ -140,7 +142,7 @@ async def asset_files(
api_blueprint.add_route(asset_files, f"/{ASSETS_PATH.name}/<path:path>")

async def web_module_files(
request: request.Request,
request: request.Request[Any, Any],
path: str,
_: str = "", # this is not used
) -> response.HTTPResponse:
Expand All @@ -159,7 +161,9 @@ def _setup_single_view_dispatcher_route(
options: Options,
) -> None:
async def model_stream(
request: request.Request, socket: WebSocketConnection, path: str = ""
request: request.Request[Any, Any],
socket: WebSocketConnection,
path: str = "",
) -> None:
asgi_app = getattr(request.app, "_asgi_app", None)
scope = asgi_app.transport.scope if asgi_app else {}
Expand Down Expand Up @@ -220,7 +224,7 @@ async def sock_recv() -> Any:
class _SanicCarrier:
"""A simple wrapper for holding connection information"""

request: request.Request
request: request.Request[Sanic[Any, Any], Any]
"""The current request object"""

websocket: WebSocketConnection
Expand Down
2 changes: 1 addition & 1 deletion src/py/reactpy/reactpy/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _render_component(
old_parent_model = parent.model.current
old_parent_children = old_parent_model["children"]
parent.model.current = {
**old_parent_model, # type: ignore[misc]
**old_parent_model,
"children": [
*old_parent_children[:index],
new_state.model.current,
Expand Down