Skip to content

Conversation

sansyrox
Copy link
Member

@sansyrox sansyrox commented Sep 12, 2025

Description

This PR fixes #

Summary

This PR does....

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

High-level PR Summary

This PR adds Pydantic support to the Robyn web framework, introducing a more modern, type-safe parameter parsing system. The implementation includes new parameter types (Query, Path, Header, Form) that enable automatic type conversion, validation, and better developer experience. The PR adds the necessary integration with Pydantic models for request body validation, comprehensive documentation in ADVANCED_PARAMS.md, example applications, and integration tests. The router has been modified to try advanced parameter parsing first before falling back to the original Robyn parameter handling logic, ensuring backward compatibility.

⏱️ Estimated Review Time: 1h 30m

💡 Review Order Suggestion
Order File Path
1 robyn/advanced_params.py
2 robyn/router.py
3 robyn/__init__.py
4 ADVANCED_PARAMS.md
5 examples/advanced_params_example.py
6 integration_tests/test_advanced_params.py
7 quick_start_example.py
8 pyproject.toml

Review by RecurseML

🔍 Review performed on ffb7ebc..7bbfa0a

Severity Location Issue Action
Low integration_tests/test_advanced_params.py:15 Redundant comment stating the obvious Dismiss
Low integration_tests/test_advanced_params.py:45 Redundant comment stating the obvious Dismiss
Low integration_tests/test_advanced_params.py:54 Redundant comment stating the obvious Dismiss
Low integration_tests/test_advanced_params.py:98 Redundant comment stating the obvious Dismiss
Low integration_tests/test_advanced_params.py:140 Redundant comment stating the obvious Dismiss
Low quick_start_example.py:23 Redundant comment that restates the obvious code action Dismiss
Low quick_start_example.py:36 Docstring restates information already clear from function signature Dismiss
Low quick_start_example.py:131 Redundant inline comment restating obvious parameter type information Dismiss
Low quick_start_example.py:117 Docstring restates obvious functionality without adding value Dismiss
Low robyn/advanced_params.py:42 Redundant docstring that restates what is clear from the function name and signature Dismiss
Low robyn/advanced_params.py:62 Redundant docstring that restates the obvious function purpose Dismiss
Low robyn/advanced_params.py:109 Redundant docstring that provides no additional context Dismiss
Low robyn/advanced_params.py:142 Redundant docstring that adds no value beyond function name Dismiss
Low robyn/advanced_params.py:185 Redundant docstring that duplicates function name meaning Dismiss
Low robyn/advanced_params.py:204 Redundant docstring that restates the obvious function purpose Dismiss
Low examples/advanced_params_example.py:35 Redundant self-documenting code comment Dismiss
Low examples/advanced_params_example.py:47 Redundant self-documenting code comment Dismiss
Low examples/advanced_params_example.py:58 Redundant self-documenting code comment Dismiss
Low examples/advanced_params_example.py:73 Redundant self-documenting code comment Dismiss
Low robyn/router.py:138 Redundant comment that restates the obvious code action Dismiss
Low robyn/router.py:145 Redundant comment that restates what is already clear from the code and logging Dismiss
Low robyn/router.py:148 Redundant comment that repeats information already clear from code context Dismiss
✅ Files analyzed, no issues (1)

robyn/__init__.py

⏭️ Files skipped (trigger manually) (2)
Locations Trigger Analysis
ADVANCED_PARAMS.md Analyze
pyproject.toml Analyze

Analyze latest changes

Need help? Join our Discord

Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
robyn Error Error Sep 12, 2025 11:05pm

"""Setup test app with advanced parameter routes."""
app = Robyn(__file__)

# Test Query parameters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as it's obvious from the code and route definitions that follow that these are query parameter tests. The code itself tells us what is being tested through the route paths and parameter types.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Test Query parameters

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

def query_alias(user_name: str = Query(..., alias="username")):
return {"user_name": user_name}

# Test Path parameters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as the code that follows clearly shows through the route definitions and Path parameter usage that these are path parameter tests.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Test Path parameters

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

def path_typed(user_id: int = Path(...), score: float = Path(...)):
return {"user_id": user_id, "score": score}

# Test Header parameters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as the subsequent code clearly demonstrates through the route definitions and Header parameter usage that these are header parameter tests.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Test Header parameters

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

"user_id": user_id
}

# Test mixed parameters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as the code that follows clearly shows through the mixed use of Path, Query and Header parameters that this tests mixed parameter handling.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Test mixed parameters

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

def test_handler(name: str = Query(...)):
return {"name": name}

# Mock request
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as it's obvious from the MockRequest class definition that follows that this is creating a mock request object.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Mock request

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

from robyn import Robyn, Query, Path, Header


# Create the app
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant and violates the effective comments rule as it merely restates what is obvious from the code app = Robyn(__file__) in the next line. The code is self-explanatory and doesn't need this comment.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Create the app

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

in_stock: bool = Query(True, description="Only in-stock items"),
categories: List[str] = Query([], description="Categories to filter by")
):
"""Search products with automatic type conversion."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is redundant as it merely restates what is already obvious from the function name 'search_products' and its type-annotated parameters. The docstring doesn't provide any additional context about why the function exists or important implementation details that aren't obvious from the code.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Search products with automatic type conversion."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

# === 5. Mixed Parameters (All Types Together) ===
@app.put("/items/:item_id")
def update_item(
user_data: CreateUserRequest, # Request body (JSON)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inline comment is redundant as it's already clear from the type annotation that this is a JSON request body parameter. The type CreateUserRequest and its usage in a PUT endpoint makes it obvious that this is the request body.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
user_data: CreateUserRequest, # Request body (JSON)
user_data: CreateUserRequest,

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)


@app.post("/users")
def create_user(user: CreateUserRequest):
"""Create user with Pydantic validation and automatic JSON parsing."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is redundant as the function name 'create_user' and the Pydantic model parameter already indicate that this endpoint creates a user with validation. The JSON parsing aspect is an implementation detail that's implicit in the framework's use of Pydantic.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Create user with Pydantic validation and automatic JSON parsing."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

self.extra = extra


def _extract_parameter_info(param: inspect.Parameter) -> Dict[str, Any]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring following this function definition is redundant and should be removed. The docstring 'Extract parameter information including type annotations and advanced parameter metadata.' adds no additional value beyond what is already clearly stated by the descriptive function name and its type hints.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)



def _parse_query_params(query_params: QueryParams, param_info: Dict[str, Any]) -> Any:
"""Parse query parameters with advanced Query objects."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is redundant and restates what is already clear from the function name '_parse_query_params'. The comment adds no additional context or explanation of complex logic that isn't already evident from the code itself.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Parse query parameters with advanced Query objects."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)



def _parse_path_params(path_params: PathParams, param_info: Dict[str, Any]) -> Any:
"""Parse path parameters with advanced Path objects."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is redundant as it merely restates what is already clear from the function name '_parse_path_params'. The comment provides no additional insight or explanation beyond what the code itself conveys.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Parse path parameters with advanced Path objects."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)



def _parse_headers(headers: Headers, param_info: Dict[str, Any]) -> Any:
"""Parse headers with advanced Header objects."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is redundant as it simply restates what the function name '_parse_headers' already clearly indicates. The comment does not provide any additional insight into complex logic or non-obvious implementation details.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Parse headers with advanced Header objects."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)



def _parse_body(body: Body, param_info: Dict[str, Any]) -> Any:
"""Parse request body with Pydantic model validation."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is redundant as it just restates what can be understood from the function name '_parse_body' and the code implementation. The comment does not provide any additional context or explanation of non-obvious behavior.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Parse request body with Pydantic model validation."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

return body


def _convert_type(value: Any, target_type: type) -> Any:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring '"""Convert value to target type."""' is redundant as it simply restates what is already clear from the function name and type hints. The comment provides no additional insight or explanation beyond what the code itself conveys.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

active: bool = Query(True, description="Whether user is active"),
tags: Optional[List[str]] = Query(None, description="Optional list of tags")
):
"""Example with typed query parameters."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is redundant as it merely restates what is already clear from the function name 'query_example' and its typed parameters. The comment adds no additional value or context beyond what the code itself expresses. According to the effective comments rule, comments should not state the obvious but rather explain 'why' when needed. This comment should be removed as the code is self-documenting.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Example with typed query parameters."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)


@app.get("/query/alias")
def query_alias_example(user_name: str = Query(..., alias="username")):
"""Example with query parameter alias."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is redundant as the function name 'query_alias_example' and the clear parameter declaration with Query(alias='username') already indicate the purpose. The comment restates what is obvious from the code. According to the effective comments rule, we should avoid comments that don't add value beyond what the code expresses.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Example with query parameter alias."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

user_id: int = Path(..., description="User ID"),
score: float = Path(..., description="User score")
):
"""Example with typed path parameters."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring violates the effective comments rule by restating what is already evident from the function name 'path_example' and its typed Path parameters. The comment does not provide any additional context or explain non-obvious assumptions. Comments should clarify intent or complexity, not restate what the code already tells us.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Example with typed path parameters."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

x_token: Optional[str] = Header(None, description="API token"),
user_agent: Optional[str] = Header(None, description="User agent")
):
"""Example with header parameters."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring simply restates what is already clear from the function name 'header_example' and its Header parameter types. The comment violates the effective comments rule by not adding any value beyond what the code itself expresses. It should be removed as it doesn't explain any non-obvious aspects or design decisions.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
"""Example with header parameters."""

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

@@ -134,6 +135,17 @@ def wrapped_handler(*args, **kwargs):
if not request or (len(handler_params) == 1 and next(iter(handler_params)) is Request):
return handler(*args, **kwargs)

# First try advanced parameter parsing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as it simply restates what the code is doing in the subsequent lines. The code itself (calling parse_advanced_params) clearly indicates that advanced parameter parsing is being attempted first.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# First try advanced parameter parsing

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

if len(advanced_params) == len(handler_params):
return handler(**advanced_params)
except Exception as e:
# If advanced parsing fails, fall back to original Robyn logic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as the following line contains a log message that already explains the fallback behavior. The code structure with try/except also makes it clear that this is a fallback path.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# If advanced parsing fails, fall back to original Robyn logic

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

# If advanced parsing fails, fall back to original Robyn logic
_logger.debug(f"Advanced parameter parsing failed, falling back to Robyn logic: {e}")

# Original Robyn parameter parsing logic as fallback
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as it restates what has already been communicated through both the code structure (try/except fallback pattern) and the explicit debug log message above.

📚 Relevant Docs

🔍 This comment matches your effective_comments.mdc rule.

Suggested change
# Original Robyn parameter parsing logic as fallback

React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

Copy link

codspeed-hq bot commented Sep 12, 2025

CodSpeed Performance Report

Merging #1247 will not alter performance

Comparing feat/pydantic-support (b15cabb) with main (a77063a)1

Summary

✅ 150 untouched

Footnotes

  1. No successful run was found on main (ffb7ebc) during the generation of this report, so a77063a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant