Repository navigation
nixoslogo: fix all type errors and most lint findings - #77
Merged
Merged
Conversation
Rework so we don't need the conditional guard which allows type inference to work.
The abstract make_svg_elements had no return annotation and inferred None, so make_svg could not concatenate it with make_svg_background. Implementations returned tuples nested up to three deep. Three in dimensioned.py were annotated svg.SVG but returned concatenated tuples. Add flatten_svg_elements and a recursive SvgElements alias to core. The abstract and all nineteen implementations now return list[svg.Element]. svg-py declares elements as list[Element] | None. Passing tuples was an error at fifteen elements= call sites; twelve are fixed here. In dimensioned.py the concatenation operands become helper arguments. The + operator would raise TypeError once super().make_svg_elements() returned a list and the other operand was a tuple. svg-py joins nested sequences with a space. Flattening drops that whitespace from 72 of the 96 artifacts. Element ancestor paths are unchanged and compare-artifacts reports all 96 unchanged. Update the affected outputHash values. Assisted-by: Claude Code (Claude Opus 5)
The package ships inline annotations but no PEP 561 marker, so type checkers treated its own modules as untyped libraries. Clears 37 reportMissingTypeStubs warnings.
Lambda is defined in nixoslogo.logomark. clearspace.py imported it from nixoslogo.logo, which only imports it for its own use. The py.typed marker makes type checkers enforce export discipline, so this was reported as a private import.
logo is instantiated as self.logo(clear_space=...) and every caller passes a class, not an instance.
tuple[Color] is a one-element tuple. LogomarkColors members hold one, two, three and six colors, so the parameter annotation was wrong for most of them. Widen to tuple[Color, ...] in Logomark and NixosLogo.
NixosLogo stored logotype_cap_height, loader and logotype_transform as optional attributes and filled them in from _init_cap_height, _init_logotype and _init_layout, so every later use was an optional access. Replace the mutating hooks with _default_cap_height and _default_transform and assign each attribute once. LogoScale overrides _default_cap_height instead of _init_cap_height.
reference is a Fraction denominator when fractional is true and a plain divisor otherwise, so it was unannotated and inferred as int from its default while five call sites passed a float cap height.
Point, Points, Vector and Matrix are never subclassed, but twelve methods were annotated -> Self while returning the concrete class. Point.__sub__ returns a Vector for a Point and a Point for a Vector, so it needs overloads; distance has always relied on that and was reported as calling length on a Point. Vector.__matmul__ and Matrix.__matmul__ return a list, _modulus_squared returns a float, and transpose built a Matrix of tuples rather than Vectors. svg._types.Number is Decimal | float | int and describes svg attribute values, not arithmetic operands: Decimal * float is a TypeError. Use float for the thirteen annotations that take part in arithmetic. make_diagonal_line returns Points, not list[Number], and the dimension offset is a float because dimension_spacings divides by a length. Assisted-by: Claude Code (Claude Opus 5)
Point, Points, Vector and Matrix subclassed a bare Sequence, so everything read out of them was Unknown.
SVG's stroke-dasharray is a list of dash lengths; a bare number is shorthand. LineGroup declared it int, so every svg element built from an annotation config was an argument type error.
jsonpickle.encode is unannotated upstream and infers str | None; cast it like the other untyped boundaries. tuple[int] is a one-element tuple, so both spacings annotations rejected their own five-element defaults. Glyph declared character as str | None, but character=None raises TypeError from the font lookup and no caller passes it. Removing the option also fixes the filename join. _map_characters needed its own annotation so dict.get would not widen the result back to str | None. Assisted-by: Claude Code (Claude Opus 5)
Artifact comparison0 modified · 0 added · 0 deleted · 96 unchanged Download report — HTML file; open in a browser. Compared
|
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.
Clears every basedpyright error in
nixoslogoand most of the warnings.make_svg_elementsnow returns a flatlist[svg.Element]. svg joins nested sequences with a space, so flattening removes inter element whitespace from 72 of the 96 artifacts. The XML is structurally identical:compare-artifactsreports all 96 unchanged, and every element keeps the same ancestor path. The affectedoutputHashvalues are updated in the same commit.requires-pythonmoves to 3.12 fortyping.override.Assisted-by: Claude Code (Claude Opus 5)