Skip to content

Fix all ruff lint errors across AskAgent/python#426

Merged
rvguha merged 4 commits intomainfrom
lint-fixes
Apr 7, 2026
Merged

Fix all ruff lint errors across AskAgent/python#426
rvguha merged 4 commits intomainfrom
lint-fixes

Conversation

@rvguha
Copy link
Copy Markdown
Collaborator

@rvguha rvguha commented Apr 6, 2026

Summary

  • Fix all 7,292 ruff lint errors in AskAgent/python/0 remaining
  • Auto-fixed 7,161: whitespace, import sorting, f-strings, type annotations, redundant patterns
  • Manually fixed 44: bare excepts, raise-without-from, type comparisons, collapsible ifs, contextlib.suppress, loop variable bindings, unicode normalization, file context managers
  • Updated ruff.toml to suppress intentional patterns (deferred imports, asyncio fire-and-forget, deprecated typing for 3.9 compat)

Test plan

  • ruff check AskAgent/python/ passes with 0 errors
  • Server starts and returns search results on localhost:8000
  • check_connectivity.py passes 3/3

🤖 Generated with Claude Code

Auto-fixed (6,451): whitespace, import sorting, f-string cleanup,
type annotations, redundant code patterns.

Unsafe-fixed (710): trailing whitespace, deprecated typing imports,
unused variables/imports.

Manually fixed (44):
- bare except → except Exception (28 files)
- raise without from → raise ... from e (10 occurrences)
- type comparison == → is (5 occurrences)
- collapsible if statements (4)
- contextlib.suppress for try/except/pass (4)
- unused loop variables prefixed with _ (3)
- EN DASH → HYPHEN-MINUS in regex (3)
- tab → space indentation (3)
- loop variable binding in closures (2)
- file open context managers (2)
- lstrip multi-char → removeprefix (1)
- undefined local variable fix (1)
- unused import removal (1)
- simplified boolean return (1)

Updated ruff.toml to suppress intentional patterns (deferred imports,
asyncio fire-and-forget tasks, deprecated typing for 3.9 compat).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 6, 2026 02:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to eliminate Ruff lint violations across AskAgent/python/ and adjust Ruff configuration to allow a few intentional patterns.

Changes:

  • Updated ruff.toml with additional global ignores and per-file ignores.
  • Applied broad auto-fixes: import ordering, exception handling patterns, f-string simplifications, and type annotation rewrites.
  • Refactored a few handlers/utilities to use context managers and suppress patterns to satisfy lint rules.

Reviewed changes

Copilot reviewed 158 out of 166 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
ruff.toml Adds ignores/per-file-ignores to reduce noise for intentional patterns.
AskAgent/python/webserver/routes/static.py Import ordering + static path normalization tweak.
AskAgent/python/webserver/routes/oauth.py Import ordering + small handler cleanups/type hints.
AskAgent/python/webserver/routes/mcp.py Import ordering + condition simplification + exception narrowing.
AskAgent/python/webserver/routes/health.py Import ordering tweaks.
AskAgent/python/webserver/routes/conversation.py Import ordering + f-string simplification for exceptions.
AskAgent/python/webserver/routes/api.py Import ordering + type hint updates + f-string simplification.
AskAgent/python/webserver/routes/a2a.py Import ordering + condition simplification + exception narrowing.
AskAgent/python/webserver/routes/init.py Reorders route setup imports.
AskAgent/python/webserver/middleware/streaming.py Import ordering tweaks.
AskAgent/python/webserver/middleware/logging_middleware.py Import ordering tweaks.
AskAgent/python/webserver/middleware/error_handler.py Import ordering + type hint updates.
AskAgent/python/webserver/middleware/cors.py Import ordering tweaks.
AskAgent/python/webserver/middleware/auth.py Import ordering + type hint updates for sets/unions.
AskAgent/python/webserver/middleware/init.py Reorders middleware imports/exports.
AskAgent/python/webserver/mcp_wrapper.py Import ordering + f-string simplification + small refactors.
AskAgent/python/webserver/appsdk_adapter_server.py Type hint rewrites + cleanup handling via contextlib.suppress.
AskAgent/python/webserver/aiohttp_streaming_wrapper.py Type hint rewrites + cleanup handling via contextlib.suppress.
AskAgent/python/webserver/aiohttp_server.py Type hint rewrites + raise ... from e for chained exceptions.
AskAgent/python/webserver/a2a_wrapper.py Type hint rewrites + exception narrowing.
AskAgent/python/tools/remove_url_duplicates.py Type hint rewrites + exception narrowing + minor print cleanup.
AskAgent/python/tools/remove_embedding_duplicates.py Type hint rewrites + exception narrowing + minor print cleanup.
AskAgent/python/tools/extract_descriptions.py Minor file-open cleanup.
AskAgent/python/tools/compute_embeddings.py Import ordering + type hint rewrites + minor logic simplification.
AskAgent/python/tests/test_appsdk_adapter.py Import ordering tweaks.
AskAgent/python/testing/test_with_clean_db.py Import ordering + removes unused assignments.
AskAgent/python/testing/test_retrieval_with_endpoint_stats.py Import ordering + type hint rewrites + print cleanup.
AskAgent/python/testing/test_queries_and_rss.py Import ordering + type hint rewrites + small list building tweak.
AskAgent/python/testing/test_frontend.py File-open cleanup + list concatenation → unpack syntax.
AskAgent/python/testing/test_endpoint_results.py Import ordering + print cleanup.
AskAgent/python/testing/test_database_operations_simple.py Import ordering + context-managed session/get + exception string formatting.
AskAgent/python/testing/test_database_operations.py Import ordering + context-managed session/get + exception string formatting.
AskAgent/python/testing/storage/test_elasticsearch_storage.py Import ordering + type hint rewrites.
AskAgent/python/testing/site_retrieval_tests.py Type hint rewrites + validation condition simplifications.
AskAgent/python/testing/run_tests.py Import ordering + type hint rewrites.
AskAgent/python/testing/retrieval/test_elasticsearch_retrieval.py Import ordering + type hint rewrites.
AskAgent/python/testing/query_test_runner.py Import ordering + file-open cleanup + print cleanup.
AskAgent/python/testing/query_retrieval_tests.py Type hint rewrites + validation condition simplifications.
AskAgent/python/testing/mock_appsdk_tool.py Type hint rewrites + KeyboardInterrupt suppression.
AskAgent/python/testing/end_to_end_tests.py Import ordering + type hint rewrites.
AskAgent/python/testing/embedding/test_elasticsearch_embedding.py Import ordering tweaks.
AskAgent/python/testing/connectivity/snowflake_connectivity.py Import ordering + print cleanup.
AskAgent/python/testing/connectivity/inception_connectivity.py Minor whitespace/print cleanup.
AskAgent/python/testing/connectivity/check_connectivity.py Import ordering + print f-string simplification.
AskAgent/python/testing/connectivity/azure_connectivity.py Import ordering + print cleanup + minor call simplifications.
AskAgent/python/testing/check_connectivity.py Import ordering + print f-string simplification.
AskAgent/python/testing/check_config.py Import ordering tweaks.
AskAgent/python/test_shopify_debug.py Removes unused import.
AskAgent/python/test_query.py Import ordering + context-managed session/get + minor cleanup.
AskAgent/python/test_prompt.ipynb Notebook whitespace + file-open cleanup + minor loop var rename.
AskAgent/python/test_dump_qdrant.py Import ordering + print cleanup + exception narrowing.
AskAgent/python/storage_providers/qdrant_storage.py Type hint rewrites + exception narrowing + minor await-result cleanup.
AskAgent/python/storage_providers/azure_search_storage.py Import ordering + type hint rewrites.
AskAgent/python/scraping/urlsFromSitemap.py Import ordering + exception string formatting + exception narrowing.
AskAgent/python/scraping/test_scraping.py Import ordering + file-open cleanup + exception narrowing.
AskAgent/python/scraping/markupFromSite.py Import ordering + file-open cleanup.
AskAgent/python/scraping/incrementalCrawlAndLoad.py Import ordering + type hint rewrites + file-open cleanup.
AskAgent/python/scraping/extractMarkup.py Import ordering + file-open cleanup + exception string formatting.
AskAgent/python/scraping/expand_json_descriptions.py Import ordering + type hint rewrites + print cleanup.
AskAgent/python/scraping/expBackOffCrawl.py Import ordering + type hint rewrites + file-open cleanup.
AskAgent/python/scraping/example_usage.py Import ordering + file-open cleanup.
AskAgent/python/scraping/embedding.py Import ordering + file-open cleanup + exception string formatting.
AskAgent/python/scraping/init.py Reorders exports/imports.
AskAgent/python/retrieval_providers/utils/snowflake.py Tightens imports + error message strings simplified.
AskAgent/python/retrieval_providers/snowflake_client.py Import ordering + type hint rewrites + exception narrowing.
AskAgent/python/retrieval_providers/qdrant_retrieve.py Import ordering + type hint rewrites + exception string formatting.
AskAgent/python/retrieval_providers/cf_autorag_client.py Import ordering + type hint rewrites + exception string formatting.
AskAgent/python/misc/postgres_load.py Import ordering tweaks.
AskAgent/python/misc/podcast_scraper.py Import ordering tweaks.
AskAgent/python/misc/nlws.py Import ordering tweaks.
AskAgent/python/misc/logger/test_logging.py Import ordering + file-open cleanup.
AskAgent/python/misc/logger/set_log_level.py Loop simplification over dict iteration.
AskAgent/python/misc/logger/logging_config_helper.py Adds suppress-based flush + file-open cleanup + type hint rewrites.
AskAgent/python/misc/logger/logger.py Switches to functools.cache + suppress-based flush + type hints.
AskAgent/python/misc/json_analysis.py Minor whitespace cleanup.
AskAgent/python/misc/extractMarkup.py Import ordering + file-open cleanup + exception string formatting.
AskAgent/python/misc/embedding.py Import ordering + file-open cleanup + exception string formatting.
AskAgent/python/methods/recipe_substitution.py Minor class decl cleanup + loop var rename + string literal simplification.
AskAgent/python/methods/multi_site_query.py Import ordering + type hint rewrites + print cleanup + exception formatting.
AskAgent/python/methods/item_details.py Import ordering + type hint rewrites + modifies ask_llm call params.
AskAgent/python/methods/generate_answer.py Import ordering + exception narrowing + minor conditional simplifications.
AskAgent/python/methods/cricket_query.py Import ordering + class decl cleanup.
AskAgent/python/methods/cricketLens.py Import ordering + type hint rewrites + context-managed session/post.
AskAgent/python/methods/conversation_search.py Import ordering + class decl cleanup + exception formatting + condition simplification.
AskAgent/python/methods/compare_items.py Import ordering + class decl cleanup.
AskAgent/python/methods/accompaniment.py Import ordering + class decl cleanup.
AskAgent/python/llm_providers/snowflake.py Type hint rewrites.
AskAgent/python/llm_providers/pi_labs.py Import ordering + file-open cleanup.
AskAgent/python/llm_providers/openai.py Import ordering + type hint rewrites.
AskAgent/python/llm_providers/ollama.py Import ordering + type hint rewrites + exception formatting.
AskAgent/python/llm_providers/llm_provider.py Type hint rewrites for provider interface.
AskAgent/python/llm_providers/inception.py Import ordering + type hint rewrites + context-managed session/post.
AskAgent/python/llm_providers/huggingface.py Import ordering + type hint rewrites.
AskAgent/python/llm_providers/gemini.py Import ordering + type hint rewrites + raise ... from e.
AskAgent/python/llm_providers/azure_oai.py Import ordering + type hint rewrites + exception formatting.
AskAgent/python/llm_providers/azure_llama.py Import ordering + type hint rewrites + exception formatting.
AskAgent/python/llm_providers/azure_deepseek.py Import ordering + type hint rewrites + exception formatting.
AskAgent/python/llm_providers/anthropic.py Import ordering + type hint rewrites + string literal simplification.
AskAgent/python/embedding_providers/snowflake_embedding.py Type hint rewrites.
AskAgent/python/embedding_providers/openai_embedding.py Import ordering + type hint rewrites + exception handling tweak.
AskAgent/python/embedding_providers/ollama_embedding.py Import ordering + type hint rewrites.
AskAgent/python/embedding_providers/gemini_embedding.py Import ordering + type hint rewrites.
AskAgent/python/embedding_providers/elasticsearch_embedding.py Import ordering + type hint rewrites + raise ... from e.
AskAgent/python/embedding_providers/azure_oai_embedding.py Import ordering + type hint rewrites + log message tweak.
AskAgent/python/data_loading/qdrant_load.py Import ordering + type hint rewrites + file-open cleanup.
AskAgent/python/data_loading/process_rss_by_org.py Refactors org writing to use context managers per write batch.
AskAgent/python/data_loading/db_load_utils.py Import ordering + type hint rewrites + file-open cleanup.
AskAgent/python/core/whoRanking.py Import ordering + exception formatting + exception narrowing.
AskAgent/python/core/whoHandler.py Import ordering + exception narrowing.
AskAgent/python/core/utils/utils.py Import ordering + list build tweak + param type comparisons + llm call recording change.
AskAgent/python/core/utils/trim_schema_json.py Condition collapses + file-open refactor + exception formatting.
AskAgent/python/core/utils/trim.py Uses safer dict .get and loop simplifications.
AskAgent/python/core/utils/message_senders.py Uses contextlib.suppress + type hint rewrites.
AskAgent/python/core/utils/json_utils.py Type hint rewrites + merge logic simplification.
AskAgent/python/core/utils/appsdk_adapter.py Type hint rewrites + typing imports cleanup.
AskAgent/python/core/state.py Minor control-flow simplification.
AskAgent/python/core/ranking.py Import ordering + exception narrowing + minor boolean simplification.
AskAgent/python/core/query_analysis/required_info.py Import ordering tweaks.
AskAgent/python/core/query_analysis/relevance_detection.py Import ordering tweaks.
AskAgent/python/core/query_analysis/query_rewrite.py Import ordering + minor response handling tweak.
AskAgent/python/core/query_analysis/memory.py Import ordering tweaks.
AskAgent/python/core/query_analysis/decontextualize.py Import ordering + tuple unpacking cleanup.
AskAgent/python/core/query_analysis/analyze_query.py Import ordering + log message tweak.
AskAgent/python/core/query_analysis/init.py Removes unused import.
AskAgent/python/core/prompts.py Fixes mutable default args + simplifies logic + exception formatting.
AskAgent/python/core/post_ranking.py Import ordering + exception formatting.
AskAgent/python/core/llm.py Import ordering + raise ... from e + exception formatting.
AskAgent/python/core/fastTrack.py Import ordering + exception formatting.
AskAgent/python/core/embedding.py Type hint rewrites + condition collapse.
AskAgent/python/core/baseHandler.py Import ordering + condition collapse + type hint rewrites.
AskAgent/python/clear_qdrant_conversations.py Import ordering + print cleanup.
AskAgent/python/chatbot_interface.py Import ordering + type hint rewrites + exception formatting.
AskAgent/python/benchmark/run_speed_benchmark.py Import ordering + removes unused assignment.
AskAgent/python/app-file.py Removes unused import.
AskAgent/python/app-aiohttp.py Removes unused imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AskAgent/python/webserver/aiohttp_server.py
Comment thread AskAgent/python/webserver/routes/static.py Outdated
Comment thread AskAgent/python/webserver/routes/oauth.py Outdated
Comment thread AskAgent/python/webserver/mcp_wrapper.py Outdated
Comment thread AskAgent/python/testing/test_retrieval_with_endpoint_stats.py Outdated
Comment thread AskAgent/python/core/utils/message_senders.py Outdated
Comment thread AskAgent/python/test_query.py Outdated
Comment thread AskAgent/python/core/utils/trim_schema_json.py Outdated
Comment thread AskAgent/python/core/utils/utils.py
Comment thread AskAgent/python/testing/site_retrieval_tests.py Outdated
rvguha and others added 3 commits April 5, 2026 20:03
- Remove 6 no-op .get() calls left by auto-fixer (oauth, mcp_wrapper,
  message_senders, query_rewrite, test_query, test_retrieval_with_endpoint_stats)
- Fix static file path traversal: use .resolve() + is_relative_to() check
- Fix duplicate trim_schema_json call: store result in local
- Fix type annotation mismatch in site_retrieval_tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The path traversal fix resolved ../static relative to the wrong base,
causing the static directory to resolve outside the project root.
Now correctly strips leading ../ segments and resolves relative to
the NLWeb project root.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rvguha rvguha merged commit 052ae6e into main Apr 7, 2026
8 checks passed
rvguha added a commit that referenced this pull request Apr 7, 2026
…apps-sdk-integration/vite-7.3.2

Dependabot: bump vite 7.1.11 → 7.3.2. Lint failure is pre-existing (fixed in #426).
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.

2 participants