清理:移除后端 3 处未使用的局部变量#139
Open
Kailigithub wants to merge 1 commit into
Open
Conversation
- dependencies.py: 移除 expiration_timestamp 及其相关注释(仅在注释中引用) - statistics.py: 移除 get_user_trend 中未使用的 records DB 查询 - statistics.py: 移除 get_user_calendar 中未使用的 start_date - python_executor.py: Docker 不可用分支的 except Exception as e 改为 except Exception(变量未在分支中使用) 行为完全不变,仅清理死代码。
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修改说明
ruff check app/ --select F841在后端代码中仍报告 4 处未使用的局部变量。本次提交清理这些死代码,不改变任何运行时行为。修改内容
tm-backend/app/dependencies.pyexpiration_timestamp及其相关注释(变量仅在被注释掉的代码中引用)tm-backend/app/routers/statistics.pyget_user_trend中无用的records = db.query(Users)...first()查询(结果未使用)tm-backend/app/routers/statistics.pyget_user_calendar中未使用的start_datetm-backend/app/services/python_executor.pyexcept Exception as e→except Exception(e在分支体中未使用)背景
之前 PR #133、#138 已覆盖大部分 F841 警告,本次清理剩余 4 处:
expiration_timestamp位于get_current_user函数,原始代码仅在被注释掉的几行中引用,属于废弃调试代码records查询位于get_user_trend函数,查询结果从未被使用,函数体直接返回随机生成的模拟数据start_date位于get_user_calendar函数,函数内部直接遍历finished_tasks累加daily_data,从未使用日期范围except Exception as e在_execute_with_docker的 Docker 不可用回退分支,e在该分支体中未被引用收益
get_user_trend每次调用减少一次 SQL 往返)验证
python3 -m py_compile app/dependencies.py app/routers/statistics.py app/services/python_executor.py通过python3 -m ruff check app/dependencies.py app/routers/statistics.py app/services/python_executor.py --select F841通过python3 -m ruff check app/dependencies.py app/routers/statistics.py app/services/python_executor.py --select F821通过(确认无Undefined name 'e'引入)imports/funcs/classes数量符合预期)影响范围
仅删除未使用的局部变量与一处已注释的废弃代码块。
dependencies.py中 4 处 B904(#135 已处理)、statistics.py中同类 B904(#134 已处理)、python_executor.py:87 code_lower(#138 已处理)均与本 PR 不重叠。