Skip to content

Commit 1651246

Browse files
committed
update based on latest template
1 parent a173c94 commit 1651246

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

peps/pep-0781.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ and would help with writing type-hinted code for memory-constrained
3737
environments like WASM or micropython.
3838

3939

40+
Rationale
41+
=========
42+
43+
Using Keyword
44+
-------------
45+
46+
Avoiding the addition of a new :ref:`keyword <python:keywords>`
47+
(like :data:`__debug__`) would be attractive because more keywords means more
48+
complex language.
49+
50+
However, adding a constant without a keyword (like :data:`__debug__`) requires
51+
special handling in both the compiler and runtime.
52+
53+
By implementing ``__type_checking__`` the same way as ``False``, we avoid the
54+
need for the special handling.
55+
Therefore, making it a keyword is the simpler approach.
56+
57+
4058
Specification
4159
=============
4260

@@ -49,23 +67,7 @@ Similar to :data:`typing.TYPE_CHECKING`, type checking tools should treat
4967
``__type_checking__`` as ``True``.
5068

5169

52-
Rationale
53-
=========
54-
55-
Difference from ``__debug__``
56-
-----------------------------
57-
58-
:data:`__debug__` is not a keyword, but a built-in constant.
59-
Not adding a new keyword is attractive, but it requires special handling in
60-
both the compiler and the runtime to change the value of the constant
61-
depending on the startup option.
62-
63-
By implementing ``__type_checking__`` the same way as ``False``,
64-
we avoid the need for special handling in both the compiler and runtime.
65-
Therefore, making it a keyword is the simpler approach.
66-
67-
68-
How to teach this
70+
How to Teach This
6971
=================
7072

7173
Add this note to the ``typing.TYPE_CHECKING`` document:

0 commit comments

Comments
 (0)