Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Two location guards test presence rather than lock, so alt/az can be computed at 0,0

未关闭 适合新手
#656 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
embedded-iot

调研方向

首先阅读 python/PiFinder/calc_utils.py 和 python/PiFinder/integrator.py,然后检查 python/PiFinder/state.py 中的 Location 默认值和锁定逻辑。追踪这两个调用点及其相关测试套件;完成的标准是两者都拒绝未锁定的位置(并防御性地处理 None),且不改变 Location 的真假值或时区行为。

由索引模型根据 Issue 内容生成。

描述

bug

Found while verifying the wording for #646 (docs PR #653). Latent — no user-visible symptom today — but the guards do not express what they are trying to express, and the thing masking them is upstream and unrelated.

The problem

Two call sites guard on the presence of a Location when what they need is a locked one.

python/PiFinder/calc_utils.py:243 — calc_object_altitude():

location = shared_state.location()
dt = shared_state.datetime()
if location and dt and solution:
    aa = FastAltAz(location.lat, location.lon, dt)

python/PiFinder/integrator.py:493 — _get_alt_az():

if ra_deg is None or dec_deg is None or location is None or dt is None:
    return None, None
calc_utils.sf_utils.set_location(location.lat, location.lon, location.altitude)

Why neither guard does anything

Location is a plain @dataclass (state.py:196) with no __bool__ and no __len__, so every instance is truthy. And the field is initialized to a real object, not None:

self.__location: Location = Location()     # state.py:295

whose defaults are lat = 0.0, lon = 0.0, lock = False. So if location is always true, and location is None is essentially always false.

The guards therefore reduce to if dt and solution and if ra/dec and dt. A path that sets a datetime without a lock computes alt/az for an observer at 0°N 0°E — Null Island, in the Gulf of Guinea. The result is a plausible-looking number that is wrong by however far the user is from there.

Why nothing breaks today

Both are reached through UI paths already gated on shared_state.altaz_ready() (state.py:332), which does test location.lock. The masking is upstream and incidental — nothing in either function records that it depends on a caller checking lock first.

Suggested fix

Guard on location.lock at both sites, matching altaz_ready(). Defining __bool__ on Location to mean "locked" would make the existing if location read correctly, but that is a wider change with its own trap: if location would then be false for a perfectly valid unlocked Location, and state.py:544 (if self.__location and self.__location.timezone) relies on current truthiness for timezone resolution, which has nothing to do with lock. Explicit location.lock at the two call sites is the smaller and clearer change.

Note set_location() (state.py:471) does assign v unconditionally, so None is technically reachable through it. Keeping a None check alongside a lock check is defensible; testing only for None is not.

主要语言
Jupyter Notebook
星标
253
派生
63
平均合并
11 小时 55 分钟
30 天内合并 PR
8

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

brickbots/PiFinder 的其他 Issue

查看 brickbots/PiFinder 的全部 Issue

相似的 Issue

更多 Embedded & IoT Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。