Skip to content

More type improvements#587

Merged
jelmer merged 5 commits intotesting-cabal:masterfrom
stephenfin:typing
Mar 14, 2026
Merged

More type improvements#587
jelmer merged 5 commits intotesting-cabal:masterfrom
stephenfin:typing

Conversation

@stephenfin
Copy link
Contributor

A grab bag of small tweaks.

  • typing: Use Sized for has_len
  • typing: Use paramspec for MonkeyPatcher
  • typing: Correct type of _raise_force_fail_error
  • typing: Make Nullary generic
  • typing: Split assertRaises context manager overload

This ensures the thing we pass actually has a length.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Stephen Finucane <stephen@that.guru>
This will always raise an exception.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This ensures that we don't lose type information for the return
value.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This ensures we don't lose type information on the `exception` attribute
of the context manager:

  with self.assertRaises(ValueError) as ctx:
      int("foo")

  reveal_type(ctx.exception)  # now reveals ValueError

We also narrow the tuple type, but varadic expansion is not a thing yet,
so we need explicitly type for different lengths of tuple. We decide
that at most 3 exceptions can be passed: any more and you'll lose this
information, which seems fair.

Signed-off-by: Stephen Finucane <stephen@that.guru>
@jelmer jelmer merged commit e6ec2fc into testing-cabal:master Mar 14, 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