FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python lint: Ruff rules for pylint and code complexity by cclauss · Pull Request #525 · modelcontextprotocol/python-sdk · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) .toml  (1) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 22 additions & 4 deletions pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,36 @@ executionEnvironments = [
{ root = "examples/servers", reportUnusedFunction = false },
]

[tool.ruff.lint]
select = ["C4", "E", "F", "I", "PERF", "UP"]
ignore = ["PERF203"]

[tool.ruff]
line-length = 120
target-version = "py310"
extend-exclude = ["README.md"]

[tool.ruff.lint]
select = [
"C4", # flake8-comprehensions
"C90", # mccabe
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"PERF", # Perflint
"PL", # Pylint
"UP", # pyupgrade
]
ignore = ["PERF203", "PLC0415", "PLR0402"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"PLC0415" and "PLR0402" are newly added.

I'm assuming that's because we've added to the selection of tools above causing new lint errors to appear that we previously were ignoring by omission?

If so I'm OK with this trade-off in the short term to have a bit more manageable complexity.

mccabe.max-complexity = 24 # Default is 10

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/server/fastmcp/test_func_metadata.py" = ["E501"]
"tests/shared/test_progress_notifications.py" = ["PLW0603"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not my favorite solution, but assuming the same thing applies as above - we have this code already, we were just ignoring it by omission.

PLW0603


[tool.ruff.lint.pylint]
allow-magic-value-types = ["bytes", "float", "int", "str"]
max-args = 23 # Default is 5
max-branches = 23 # Default is 12
max-returns = 13 # Default is 6
max-statements = 102 # Default is 50

[tool.uv.workspace]
members = ["examples/servers/*", "examples/snippets"]
Expand Down
5 changes: 2 additions & 3 deletions src/mcp/server/fastmcp/server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ def __init__(
raise ValueError("Cannot specify both auth_server_provider and token_verifier")
if not auth_server_provider and not token_verifier:
raise ValueError("Must specify either auth_server_provider or token_verifier when auth is enabled")
else:
if auth_server_provider or token_verifier:
raise ValueError("Cannot specify auth_server_provider or token_verifier without auth settings")
elif auth_server_provider or token_verifier:
raise ValueError("Cannot specify auth_server_provider or token_verifier without auth settings")

self._auth_server_provider = auth_server_provider
self._token_verifier = token_verifier
Expand Down
6 changes: 3 additions & 3 deletions src/mcp/server/fastmcp/utilities/func_metadata.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ def pre_parse_json(self, data: dict[str, Any]) -> dict[str, Any]:
if field_info.alias:
key_to_field_info[field_info.alias] = field_info

for data_key in data.keys():
for data_key, data_value in data.items():
if data_key not in key_to_field_info:
continue

field_info = key_to_field_info[data_key]
if isinstance(data[data_key], str) and field_info.annotation is not str:
if isinstance(data_value, str) and field_info.annotation is not str:
try:
pre_parsed = json.loads(data[data_key])
pre_parsed = json.loads(data_value)
except json.JSONDecodeError:
continue # Not JSON - skip
if isinstance(pre_parsed, str | int | float):
Expand Down
1 change: 0 additions & 1 deletion src/mcp/server/lowlevel/server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ async def main():
from mcp.server.lowlevel.helper_types import ReadResourceContents
from mcp.server.models import InitializationOptions
from mcp.server.session import ServerSession
from mcp.server.stdio import stdio_server as stdio_server
from mcp.shared.context import RequestContext
from mcp.shared.exceptions import McpError
from mcp.shared.message import ServerMessageMetadata, SessionMessage
Expand Down
21 changes: 10 additions & 11 deletions src/mcp/server/streamable_http.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -838,17 +838,16 @@ async def message_router():
# If this response is for an existing request stream,
# send it there
target_request_id = response_id
else:
# Extract related_request_id from meta if it exists
if (
session_message.metadata is not None
and isinstance(
session_message.metadata,
ServerMessageMetadata,
)
and session_message.metadata.related_request_id is not None
):
target_request_id = str(session_message.metadata.related_request_id)
# Extract related_request_id from meta if it exists
elif (
session_message.metadata is not None
and isinstance(
session_message.metadata,
ServerMessageMetadata,
)
and session_message.metadata.related_request_id is not None
):
target_request_id = str(session_message.metadata.related_request_id)

request_stream_id = target_request_id if target_request_id is not None else GET_STREAM_KEY

Expand Down
Loading

Back | FazBrowse Home | New Git URL