Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make type checkers happy #3

Merged
merged 2 commits into from
Oct 14, 2024
Merged

make type checkers happy #3

merged 2 commits into from
Oct 14, 2024

Conversation

Catminusminus
Copy link
Owner

@Catminusminus Catminusminus commented Oct 13, 2024

This PR will Fix #2 and some type errors.

The following three types of type errors are currently occurring:

  • Caused by incomplete types.
  • Due to covariance.
    • If A is a subtype of B, it seems natural that Option[A] is also a subtype of Option[B]. So we use T = TypeVar("T", covariant=True) for class Some(Generic[T]):. However, because covariant type variable cannot be used in parameter type, we cannot use def unwrap_or(self, default: T) -> T:.
  • Due to Lack of runtime annotation
    • Think about Nothing().map(lambda x: x + 1). The problem is that the type of lambda x: x + 1 is not clear.
      It would be nice if we could annotate this lambda expression with the type directly, or annotate Nothing directly, but that is not possible (of course it is possible via a temporary variable, but Ruff does not allow lambdas to be put into temporary variables).

To address these issues, I did the followings:

  • Eliminated incomplete types.
  • Excluded T from the function arguments. In particular, I used Any instead.

Copy link

@qexat qexat left a comment

Choose a reason for hiding this comment

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

it looks good to me!

@Catminusminus Catminusminus merged commit 4ccb777 into main Oct 14, 2024
4 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.

Incomplete type annotations lead to error diagnostics from static type checkers
2 participants