Add Vedran's rejected proposal to PEP 526.
This commit is contained in:
parent
ff32da0bc6
commit
0b20b733b3
20
pep-0526.txt
20
pep-0526.txt
|
@ -567,6 +567,26 @@ Rejected/Postponed Proposals
|
|||
instead a TypeError will be raised if an attempt is made to update
|
||||
``__annotations__`` when it is anything other than a dict.
|
||||
|
||||
- **Treating bare annotations the same as global or nonlocal:**
|
||||
The rejected proposal would prefer that the presence of an
|
||||
annotation without assignment in a function body should not involve
|
||||
*any* evaluation. In contrast, the PEP implies that if the target
|
||||
is more complex than a single name, its "left-hand part" should be
|
||||
evaluated at the point where it occurs in the function body, just to
|
||||
enforce that it is defined. For example, in this example::
|
||||
|
||||
def foo(self):
|
||||
slef.name: str
|
||||
|
||||
the name ``slef`` should be evaluated, just so that if it is not
|
||||
defined (as is likely in this example :-), the error will be caught
|
||||
at runtime. This is more in line with what happens when there *is*
|
||||
an initial value, and thus is expected to lead to fewer surprises.
|
||||
(Also note that if the target was ``self.name`` (this time correctly
|
||||
spelled :-), an optimizing compiler has no obligation to evaluate
|
||||
``self`` as long as it can prove that it will definitely be
|
||||
defined.)
|
||||
|
||||
|
||||
Backwards Compatibility
|
||||
=======================
|
||||
|
|
Loading…
Reference in New Issue