Skip to content

Tighten return types of always-succeeding to_affine() - #81

Merged
clbarnes merged 1 commit into
clbarnes:mainfrom
Tomaz-Vieira:successful_to_affine
Jul 28, 2026
Merged

Tighten return types of always-succeeding to_affine()#81
clbarnes merged 1 commit into
clbarnes:mainfrom
Tomaz-Vieira:successful_to_affine

Conversation

@Tomaz-Vieira

Copy link
Copy Markdown
Contributor

Some transformations always succeed when calling .to_affine(), but their method signature still returns Affine | None. This patch tightens their types to simply return Affine when we know they always succeed. This is still compatible with the parent signature (i.e. Affine is a subtype of Affine | None), but is convenient for code that is dealing with concrete children of Transform, since they don't have to assert that to_affine() is not None:

# before:
def use_scale(scale: Scale):
    scale_affine = scale.to_affine()
    assert scale_affine is not None
    use_affine(scale_affine)

# after
def use_scale2(scale: Scale):
    scale_affine = scale.to_affine()
    use_affine(scale_affine)

@clbarnes

Copy link
Copy Markdown
Owner

If type checkers are happy with this narrowing, that's perfect!

@clbarnes
clbarnes merged commit 3869435 into clbarnes:main Jul 28, 2026
9 checks passed
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