Repository navigation
gh-103921: Document PEP 695 #104642
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
gh-103921: Document PEP 695 #104642
Changes from 1 commit
786a436
c1f266e
040c4fd
e3dfb27
f5b1d86
5798631
0f76679
cb76021
12c1249
94a4da2
815a021
17ac785
1311399
123752c
9d6e0c0
e955a45
d7f2b55
53c4916
edec8c3
bc1c1d2
b1a843c
e690aff
cc5b51c
b0e1ce3
382ff2c
db94e4f
18b9d63
b7ba811
fd1d0a8
62ba887
200eba1
adaf874
4481d6d
365ae7b
96e5d16
0204d54
f426d39
60d7783
63d4d84
fd6751a
499dae1
b4172c9
e9bc4a8
0d37675
c94ee7c
1630342
aade45a
57b9992
7953d2c
9128c72
0511b6a
4fd3f02
fff0df4
ba2a103
1c6807d
6386475
cd4206c
e307177
d7e1c6c
f878970
a4bd32a
ee8f952
7a709d7
0cfeb92
f978766
bba092d
57ddbef
67acd98
988fc7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
|
AlexWaygood marked this conversation as resolved.
JelleZijlstra marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -443,42 +443,42 @@ static PyMethodDef typevar_methods[] = { | |||
| PyDoc_STRVAR(typevar_doc, | ||||
| "Type variable.\n\ | ||||
| \n\ | ||||
| Usage::\n\ | ||||
| The preferred way to construct a type variable is via the dedicated syntax\n\ | ||||
| for :ref:`generic functions <generic-functions>`,\n\ | ||||
| :ref:`generic classes <generic-classes>`, and\n\ | ||||
| :ref:`generic type aliases <generic-type-aliases>`::\n\ | ||||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||||
| \n\ | ||||
| T = TypeVar('T') # Can be anything\n\ | ||||
| S = TypeVar('S', bound=str) # Can be any subtype of str\n\ | ||||
| A = TypeVar('A', str, bytes) # Must be str or bytes\n\ | ||||
| class Sequence[T]: # T is a TypeVar\n\ | ||||
| ...\n\ | ||||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||||
| \n\ | ||||
| The syntax for generic functions, classes, and type aliases can\n\ | ||||
| be used to create type variables::\n\ | ||||
| This syntax can also be used to create bound and constrained type\n\ | ||||
| variables::\n\ | ||||
| \n\ | ||||
| class Sequence[T]: # T is a TypeVar\n\ | ||||
| ...\n\ | ||||
| class StrSequence[S: str]: # S is a TypeVar bound to str\n\ | ||||
| ...\n\ | ||||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||||
| \n\ | ||||
| Type variables exist primarily for the benefit of static type\n\ | ||||
| checkers. They serve as the parameters for generic types as well\n\ | ||||
| as for generic function definitions. See class Generic for more\n\ | ||||
| information on generic types. Generic functions work as follows:\n\ | ||||
| \n\ | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think two line breaks are necessary here
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, fixed. Also thanks for all the thorough reviews! I am going to merge this now so I can stop worrying about conflicts.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, it's time :) |
||||
| def repeat[T](x: T, n: int) -> Sequence[T]:\n\ | ||||
| '''Return a list containing n references to x.'''\n\ | ||||
| return [x]*n\n\ | ||||
| class StrOrBytesSequence[A: (str, bytes)]: # A is a TypeVar constrained to str or bytes\n\ | ||||
| ...\n\ | ||||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||||
| \n\ | ||||
| def print_capitalized[S: str](x: S) -> S:\n\ | ||||
| '''Print x capitalized, and return x.'''\n\ | ||||
| print(x.capitalize())\n\ | ||||
| return x\n\ | ||||
| However, if desired, reusable type variables can also be constructed\n\ | ||||
| manually, like so::\n\ | ||||
| \n\ | ||||
| def concatenate[A: (str, bytes)](x: A, y: A) -> A:\n\ | ||||
| '''Add two strings or bytes objects together.'''\n\ | ||||
| return x + y\n\ | ||||
| T = TypeVar('T') # Can be anything\n\ | ||||
| S = TypeVar('S', bound=str) # Can be any subtype of str\n\ | ||||
| A = TypeVar('A', str, bytes) # Must be exactly str or bytes\n\ | ||||
| \n\ | ||||
| Type variables exist primarily for the benefit of static type\n\ | ||||
| checkers. They serve as the parameters for generic types as well\n\ | ||||
| as for generic function and type alias definitions.\n\ | ||||
| \n\ | ||||
| The variance of type variables is inferred by type checkers when they are created\n\ | ||||
| through the type parameter syntax and when\n\ | ||||
| ``infer_variance=True`` is passed.\n\ | ||||
| Manually created type variables may be explicitly marked covariant or contravariant by passing\n\ | ||||
| ``covariant=True`` or ``contravariant=True``. See PEP 484 and PEP 695 for more\n\ | ||||
| details. By default, type variables are invariant.\n\ | ||||
| Manually created type variables may be explicitly marked covariant or\n\ | ||||
| contravariant by passing ``covariant=True`` or ``contravariant=True``.\n\ | ||||
| By default, manually created type variables are invariant. See PEP 484\n\ | ||||
| and PEP 695 for more details.\n\ | ||||
| "); | ||||
|
|
||||
| static PyType_Slot typevar_slots[] = { | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.