Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 305
add LiteralString#1053
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
Uh oh!
There was an error while loading. Please reload this page.
add LiteralString #1053
Changes from all commits
f8a564c5eae6e8ca0f9902fc8d6508c65a553edacc6a442f64bf9cac54e7c3abcce9a7ec9f531File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,7 +22,7 @@ | ||
| from typing_extensions import TypeAlias, ParamSpec, Concatenate, ParamSpecArgs, ParamSpecKwargs, TypeGuard | ||
| from typing_extensions import Awaitable, AsyncIterator, AsyncContextManager, Required, NotRequired | ||
| from typing_extensions import Protocol, runtime, runtime_checkable, Annotated, overload, final, is_typeddict | ||
| from typing_extensions import dataclass_transform, reveal_type, Never, assert_never | ||
| from typing_extensions import dataclass_transform, reveal_type, Never, assert_never, LiteralString | ||
| try: | ||
| from typing_extensions import get_type_hints | ||
| except ImportError: | ||
| @@ -111,6 +111,11 @@ def test_cannot_instantiate(self): | ||
| with self.assertRaises(TypeError): | ||
| type(self.bottom_type)() | ||
| def test_pickle(self): | ||
| for proto in range(pickle.HIGHEST_PROTOCOL): | ||
| pickled = pickle.dumps(self.bottom_type, protocol=proto) | ||
| self.assertIs(self.bottom_type, pickle.loads(pickled)) | ||
| class NoReturnTests(BottomTypeTestsMixin, BaseTestCase): | ||
| bottom_type = NoReturn | ||
| @@ -1896,7 +1901,8 @@ def test_cannot_check_subclass(self): | ||
| def test_pickle(self): | ||
| samples = [typing.Any, typing.Union[int, str], | ||
| typing.Optional[str], Tuple[int, ...], | ||
| typing.Callable[[str], bytes]] | ||
| typing.Callable[[str], bytes], | ||
| Self, LiteralString, Never] | ||
| for t in samples: | ||
| x = Annotated[t, "a"] | ||
| @@ -2290,6 +2296,67 @@ def test_no_isinstance(self): | ||
| issubclass(int, TypeGuard) | ||
| class LiteralStringTests(BaseTestCase): | ||
| def test_basics(self): | ||
| class Foo: | ||
| def bar(self) -> LiteralString: ... | ||
| def baz(self) -> "LiteralString": ... | ||
| self.assertEqual(gth(Foo.bar), {'return': LiteralString}) | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| self.assertEqual(gth(Foo.baz), {'return': LiteralString}) | ||
| @skipUnless(PEP_560, "Python 3.7+ required") | ||
| def test_get_origin(self): | ||
| from typing_extensions import get_origin | ||
| self.assertIsNone(get_origin(LiteralString)) | ||
| def test_repr(self): | ||
| if hasattr(typing, 'LiteralString'): | ||
| mod_name = 'typing' | ||
| else: | ||
| mod_name = 'typing_extensions' | ||
| self.assertEqual(repr(LiteralString), '{}.LiteralString'.format(mod_name)) | ||
| def test_cannot_subscript(self): | ||
| with self.assertRaises(TypeError): | ||
| LiteralString[int] | ||
| def test_cannot_subclass(self): | ||
| with self.assertRaises(TypeError): | ||
| class C(type(LiteralString)): | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| pass | ||
| with self.assertRaises(TypeError): | ||
| class C(LiteralString): | ||
| pass | ||
| def test_cannot_init(self): | ||
| with self.assertRaises(TypeError): | ||
| LiteralString() | ||
| with self.assertRaises(TypeError): | ||
| type(LiteralString)() | ||
| def test_no_isinstance(self): | ||
| with self.assertRaises(TypeError): | ||
| isinstance(1, LiteralString) | ||
| with self.assertRaises(TypeError): | ||
| issubclass(int, LiteralString) | ||
| def test_alias(self): | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| StringTuple = Tuple[LiteralString, LiteralString] | ||
| class Alias: | ||
| def return_tuple(self) -> StringTuple: | ||
| return ("foo", "pep" + "675") | ||
| def test_typevar(self): | ||
| StrT = TypeVar("StrT", bound=LiteralString) | ||
| self.assertIs(StrT.__bound__, LiteralString) | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_pickle(self): | ||
| for proto in range(pickle.HIGHEST_PROTOCOL): | ||
| pickled = pickle.dumps(LiteralString, protocol=proto) | ||
| self.assertIs(LiteralString, pickle.loads(pickled)) | ||
| class SelfTests(BaseTestCase): | ||
| def test_basics(self): | ||
| class Foo: | ||
| @@ -2331,6 +2398,11 @@ class Alias: | ||
| def return_tuple(self) -> TupleSelf: | ||
| return (self, self) | ||
| def test_pickle(self): | ||
| for proto in range(pickle.HIGHEST_PROTOCOL): | ||
| pickled = pickle.dumps(Self, protocol=proto) | ||
| self.assertIs(Self, pickle.loads(pickled)) | ||
| class FinalDecoratorTests(BaseTestCase): | ||
| def test_final_unmodified(self): | ||
Uh oh!
There was an error while loading. Please reload this page.