pyembroidery icon indicating copy to clipboard operation
pyembroidery copied to clipboard

Fix type errors

Open not-my-profile opened this issue 8 months ago • 2 comments

I'm currently working on making the codebase type check with pyright.

From the 180 type errors in src on main I'm already down to 43. The following questions remain:

  • DatReader is calling a needle_out method on the out: EmbPattern which doesn't exist, apparently this bug has existed since the code was introduced in 6187bd393542deada5f90726d662b73565a032a4
  • Should the stitch coordinates be int or float? Most readers seem to read integers, however some are currently reading floats (e.g. MitReader due to the MIT_SIZE_CONVERSION_RATIO and CsvReader explicitly converts the coordinates to float).

/cc @kaalleen

not-my-profile avatar Aug 04 '25 05:08 not-my-profile

Uh, I really don't know much about it. I honestly never spend a lot of time with pyembroidery so far, only if it was really, really necessary.

Maybe @lexelby has a better insight?

kaalleen avatar Aug 04 '25 19:08 kaalleen

@not-my-profile Thanks for taking this on!

That needle_out() thing is a mystery. My best guess is that this should be out.needle_change(needle).

I did quite a bit of digging to figure out the float vs int question, until I finally came across this buried in the README:

The core units are 1/10th mm. This is what 1 refers to within most formats, and internally within pystitch itself. You are entirely permitted to use floating point numbers. When writing to a format, fractional values will be lost, but this shall happen in such a way to avoid the propagation of error.

I've checked, and Ink/Stitch is written to expect floating point coordinates when reading embroidery design files, so we're good on the Ink/Stitch side.

So with all this in mind, I think EmbPattern should have coordinates typed as floats, and from my understanding, pyright ought to be willing to accept readers passing ints to things like EmbPattern.stitch, etc, without a cast.

lexelby avatar Aug 21 '25 16:08 lexelby