Skip to content

Conversation

@juanitorduz
Copy link

@juanitorduz juanitorduz commented Oct 21, 2025

Here is a rather pragmatic suggestion since its hard to make it work

Comment on lines +356 to +358
base_constraint: ConstraintT
reinterpreted_batch_ndims: int

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a factory function over these changes. What are your thoughts?

Comment on lines +43 to +54
# ConstraintLike represents any constraint object (both Constraint[NumLike] and
# Constraint[NonScalarArray]). We use Any because:
# 1. Constraint[T] is a generic class, and mypy struggles with Protocol subtyping
# of generic classes due to variance issues
# 2. Some constraints only accept NonScalarArray while others accept full NumLike,
# making a single Protocol definition either too restrictive or too permissive
# 3. Creating a structural Protocol causes mypy errors when assigning concrete
# constraint instances to protocol-typed variables
# At runtime, all constraints share the interface (is_discrete, event_dim, __call__, etc.)
# and work correctly. This type alias provides better documentation than raw `Any`
# while acknowledging the limitations of Python's type system for this use case.
ConstraintLike: TypeAlias = Any
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this defeating the purpose of why we are introducing the types?

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