Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_http_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement dummy ``__class_getitem__`` for ``http.cookies.Morsel``.