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

Add not_none #7

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

JelleZijlstra
Copy link
Collaborator

No description provided.



def test(x: Any, y: str | None, z: str) -> None:
assert_type(not_none(x), Any)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mypy fails on this one:

static_tests/test_not_none.py:10: error: Expression is of type <nothing>, not "Any"  [assert-type]

Possibly fixable with overloads, let me try that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, now pyright fails with something worse:

  /home/runner/work/useful_types/useful_types/static_tests/test_not_none.py:10:17 - error: "assert_type" mismatch: expected "Any" but received "Never" (reportGeneralTypeIssues)

I think I prefer the version without overloads.

Copy link
Owner

Choose a reason for hiding this comment

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

I think might work with both if you reorder overloads?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, that way it doesn't narrow away the None at all, because None matches the first overload.

Copy link
Owner

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Can we use an if MYPY trick to unblock this?

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