Skip to content

Prefer typed math implementations during type checking - #1405

Closed
eevleevs wants to merge 2 commits into
mozman:masterfrom
eevleevs:fix/type-check-c-extension
Closed

Prefer typed math implementations during type checking#1405
eevleevs wants to merge 2 commits into
mozman:masterfrom
eevleevs:fix/type-check-c-extension

Conversation

@eevleevs

@eevleevs eevleevs commented Aug 13, 2026

Copy link
Copy Markdown

Problem

ezdxf.math._ctypes already exports Vec2, Vec3, and Matrix44, but its runtime implementation selection causes static type checkers to see Unknown | Vec3: the Cython branch has no Python typing information, while the pure-Python fallback is typed.

Fix

Guard the Cython branch with not TYPE_CHECKING. Type checkers therefore select the typed pure-Python fallback, while runtime behavior remains unchanged: Cython implementations are still used whenever USE_C_EXT is true.

Validation

  • python -m py_compile src/ezdxf/math/_ctypes.py
  • git diff --check

@mozman

mozman commented Aug 14, 2026

Copy link
Copy Markdown
Owner

FYI: the current state of the repository is working:

(.venv) C:\Source\ezdxf.git
>pip list | grep mypy
mypy                          2.3.0
mypy_extensions               1.1.0

(.venv) C:\Source\ezdxf.git
>make mypy
mypy --ignore-missing-imports -p ezdxf
Success: no issues found in 343 source files

@eevleevs

Copy link
Copy Markdown
Author

Added commit 95ee679 with the follow-up type fixes. This PR changes mypy's view of ezdxf.math._ctypes so it uses the typed Python implementations instead of treating the C extensions as unresolved/Any. That exposed type errors that were already present in the codebase; the follow-up fixes address those preexisting issues. Runtime C-extension selection is unchanged.\n\nValidation:\n- python -m mypy --ignore-missing-imports src/ezdxf\n- No issues found in 341 source files\n- 7121 tests passed, 30 skipped, 1 xfailed\n\nDrawing tests were excluded because PIL is not installed locally.

@mozman

mozman commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Just NO!

@mozman mozman closed this Aug 19, 2026
@eevleevs

Copy link
Copy Markdown
Author

Quite rude, care to explain why? Consider that this shows you have many suppressed inconsistencies in your codebase.

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.

2 participants