Skip to content

清理:移除后端 3 处未使用的局部变量#139

Open
Kailigithub wants to merge 1 commit into
datawhalechina:mainfrom
Kailigithub:fix/ruff-f841-remaining-deadcode
Open

清理:移除后端 3 处未使用的局部变量#139
Kailigithub wants to merge 1 commit into
datawhalechina:mainfrom
Kailigithub:fix/ruff-f841-remaining-deadcode

Conversation

@Kailigithub

Copy link
Copy Markdown
Collaborator

修改说明

ruff check app/ --select F841 在后端代码中仍报告 4 处未使用的局部变量。本次提交清理这些死代码,不改变任何运行时行为。

修改内容

文件 修改
tm-backend/app/dependencies.py 53-58 移除 expiration_timestamp 及其相关注释(变量仅在被注释掉的代码中引用)
tm-backend/app/routers/statistics.py 108-111 移除 get_user_trend 中无用的 records = db.query(Users)...first() 查询(结果未使用)
tm-backend/app/routers/statistics.py 587 移除 get_user_calendar 中未使用的 start_date
tm-backend/app/services/python_executor.py 176 except Exception as eexcept Exceptione 在分支体中未使用)

背景

之前 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 在该分支体中未被引用

收益

  • 减少后端 ruff F841 警告 4 处
  • 删除一处无用 DB 查询(get_user_trend 每次调用减少一次 SQL 往返)
  • 与已有清理类 PR 风格保持一致

验证

  • 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' 引入)
  • AST parse 验证模块结构完整(imports/funcs/classes 数量符合预期)

影响范围

仅删除未使用的局部变量与一处已注释的废弃代码块。dependencies.py 中 4 处 B904(#135 已处理)、statistics.py 中同类 B904(#134 已处理)、python_executor.py:87 code_lower#138 已处理)均与本 PR 不重叠。

- 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(变量未在分支中使用)

行为完全不变,仅清理死代码。
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