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

assert_unreachable function #147

Closed
DetachHead opened this issue Jan 12, 2022 · 5 comments
Closed

assert_unreachable function #147

DetachHead opened this issue Jan 12, 2022 · 5 comments

Comments

@DetachHead
Copy link
Collaborator

DetachHead commented Jan 12, 2022

KotlinIsland/basedtyping#28
would need to invert the unreachable error code when it sees an assert_unreachable call, such that it's raised if the code is reachable. perhaps a seperate error code?

when warn-unreachable is enabled

if False:
  assert_unreachable() # no error
if False:
  print(1) #error: unreachable
  assert_unreachable() # no error
else:
  assert_unreachable() # error

When warn-unreachable is disabled

if False:
  print(1) # no error
  assert_unreachable() # no error
else:
  assert_unreachable() # error
@KotlinIsland
Copy link
Owner

KotlinIsland commented Jan 12, 2022

Would lead up be allowed? eg:

a: float = 1

if not isinstance(a, float):
    message = "LOOL!"
    logger.warning(DuckTypingError(message))
    assert_unreachable(message)

@DetachHead
Copy link
Collaborator Author

i don't think so

@DetachHead
Copy link
Collaborator Author

DetachHead commented Jan 12, 2022

when warn-unreachable is enabled

if False:
  print(1) #error: unreachable
  assert_unreachable() # no error
else:
  assert_unreachable() # error

when warn-unreachable is disabled

if False:
  print(1) # no error
  assert_unreachable() # no error
else:
  assert_unreachable() # error

@KotlinIsland
Copy link
Owner

python/typing#735

@DetachHead
Copy link
Collaborator Author

assert_never exists now

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants