diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py index 6694f5478bdadf..85b1d766078626 100644 --- a/Lib/http/cookies.py +++ b/Lib/http/cookies.py @@ -293,6 +293,17 @@ def __init__(self): for key in self._reserved: dict.__setitem__(self, key, "") + def __class_getitem__(cls, type): + """Provide minimal support for using this class as generic + (for example in type annotations). + + See PEP 484 and PEP 560 for more details. For example, `Morsel[T]` + is a valid expression at runtime (type argument `T` indicates the + type of pair). Note, no type checking happens at runtime, but + a static type checker can be used. + """ + return cls + @property def key(self): return self._key diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py index 6072c7e15e92be..d36b163c60d02e 100644 --- a/Lib/test/test_http_cookies.py +++ b/Lib/test/test_http_cookies.py @@ -479,6 +479,9 @@ def test_repr(self): r'Set-Cookie: key=coded_val; ' r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+') + def test_class_getitem(self): + self.assertIs(cookies.Morsel[str], cookies.Morsel) + def test_main(): run_unittest(CookieTests, MorselTests) run_doctest(cookies) diff --git a/Misc/NEWS.d/next/Library/2019-12-10-21-27-37.bpo-39019.7o43Gq.rst b/Misc/NEWS.d/next/Library/2019-12-10-21-27-37.bpo-39019.7o43Gq.rst new file mode 100644 index 00000000000000..ae103eb3d74514 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-12-10-21-27-37.bpo-39019.7o43Gq.rst @@ -0,0 +1 @@ +Implement dummy ``__class_getitem__`` for ``http.cookies.Morsel``.