Skip to content

Backport assert_never change to include repr of value#371

Merged
AlexWaygood merged 3 commits intopython:mainfrom
Hnasar:backport-assert-never-value
Apr 20, 2024
Merged

Backport assert_never change to include repr of value#371
AlexWaygood merged 3 commits intopython:mainfrom
Hnasar:backport-assert-never-value

Conversation

@Hnasar
Copy link
Copy Markdown
Contributor

@Hnasar Hnasar commented Apr 19, 2024

This helps to debug what bad data you have.

Via python/cpython@93d2801#diff-ddb987fca5f5df0c9a2f5521ed687919d70bb3d64eaeb8021f98833a2a716887

$ PYTHONPATH=src python3.10
>>> import typing_extensions
>>> typing_extensions.__file__
'typing_extensions/src/typing_extensions.py'
>>> typing_extensions.assert_never("boo!")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "typing_extensions/src/typing_extensions.py", line 2387, in assert_never
    raise AssertionError(f"Expected code to be unreachable, but got: {value}")
AssertionError: Expected code to be unreachable, but got: 'boo!'

@ghost
Copy link
Copy Markdown

ghost commented Apr 19, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@Hnasar Hnasar force-pushed the backport-assert-never-value branch 2 times, most recently from 179c94a to 6d6c48a Compare April 19, 2024 19:04
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks! Could you also backport the unit tests from the linked PR?

@Hnasar Hnasar force-pushed the backport-assert-never-value branch from 6d6c48a to 84a1ac2 Compare April 19, 2024 21:02
@Hnasar
Copy link
Copy Markdown
Contributor Author

Hnasar commented Apr 19, 2024

Thanks for taking a look — tests are now included!

This helps to debug what bad data you have.

Via python/cpython@93d2801#diff-ddb987fca5f5df0c9a2f5521ed687919d70bb3d64eaeb8021f98833a2a716887

```pycon
$ PYTHONPATH=src python3.10
>>> import typing_extensions
>>> typing_extensions.__file__
'typing_extensions/src/typing_extensions.py'
>>> typing_extensions.assert_never("boo!")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "typing_extensions/src/typing_extensions.py", line 2387, in assert_never
    raise AssertionError(f"Expected code to be unreachable, but got: {value}")
AssertionError: Expected code to be unreachable, but got: 'boo!'
```
@Hnasar Hnasar force-pushed the backport-assert-never-value branch from 84a1ac2 to 46f6df7 Compare April 19, 2024 21:04
Comment thread src/test_typing_extensions.py Outdated
@Hnasar Hnasar force-pushed the backport-assert-never-value branch from 9b10c4c to ddb09b4 Compare April 19, 2024 21:32
@AlexWaygood AlexWaygood merged commit 2a7945b into python:main Apr 20, 2024
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.

3 participants