Repository navigation
Clear all 27 mypy errors in language_lens.py (#431 session 4) - #442
Merged
Merged
Conversation
Root cause + six smaller follow-on fixes: - LENS_CONFIG (language_standards.py) mixes Set[str]/Dict[str,str]/ List[Dict]/Dict[str,float] values in one dict literal, widened by mypy to Collection[object] -- the same class of bug as #436's RECORDING_SCHEMAS, producing 16 direct "Collection[object] has no attribute get/items" errors in language_lens.py plus 4 more in prism.py. Added a LensConfig TypedDict. All consumers already use literal string keys. - `target_id`: two genuinely independent uses of the same name in different branches of one function -- one always a plain str (a self-contained prose-extension shortcut that returns immediately), the other legitimately Optional[str] (an anchor-map lookup). Renamed the first to prose_target_id instead of fighting mypy's narrowing across two unrelated code paths sharing one name. - `lock_tier`: first assigned as int (4), later assigned 1.5/1.7 -- sub-tiers are intentional (see "Tier 1.5"/"Tier 1.7" in the code and DetectorResult's own lock_tier: Union[int, float]). Annotated float at declaration; _forge_result's tier: int parameter widened to match. - `local_tally`: missing annotation on an empty dict accumulator. Dict[str, int]. - Two `max(d, key=d.get)` calls: dict.get is overloaded (1-arg vs 2-arg-with-default), which mypy can't resolve when passed bare as a key function. Switched both to `key=lambda k: d[k]` -- safe since key is only ever invoked on d's own members. - `regex_hits`: assigned int(0), later multiplied by 0.7 (a language handicap). Annotated float at declaration -- its only consumer is a final `/loc` density calculation that was always going to produce a float anyway. - `_find_balanced_end`'s `limit`: self.thresholds is Dict[str, float] (mixing float confidence values with integer limits like HANDSHAKE_LOOKAHEAD_LIMIT), so the range()-bound computed from it needs an explicit int() -- a character-position limit was always meant to be a whole number. Fixed the return-value mismatch too, same root cause. 157 -> 126 unique baseline entries. Verified: language_lens.py reports zero mypy errors after this change. flake8, dead_key_audit.py --ci, full pytest suite (866 passed, 1 deselected, 1 pre-existing xfail) all clean.
Contributor
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.
Summary
Part of #429/#431, one file per session. This session: `language_lens.py` (plus `LENS_CONFIG` in `language_standards.py`, its root cause).
Root cause: `LENS_CONFIG` mixes `Set[str]`/`Dict[str,str]`/`List[Dict]`/`Dict[str,float]` values in one dict literal, widened by mypy to `Collection[object]` -- the same class of bug as #436's `RECORDING_SCHEMAS` fix, producing 16 direct errors in `language_lens.py` plus 4 more in `prism.py`. Added a `LensConfig` `TypedDict`.
Six smaller follow-on fixes, all in `language_lens.py`:
157 → 126 unique baseline entries.
Test plan