[Python-ideas] PEP 484 (Type Hints) -- first draft round
Guido van Rossum
guido at python.org
Fri Jan 16 22:34:36 CET 2015
On Fri, Jan 16, 2015 at 12:14 PM, Andrew Barnert <
abarnert at yahoo.com.dmarc.invalid> wrote:
> One quick clarification question:
> Can strings-as-forward-declarations be used inside non-string type
> annotations--e.g.. Set['Employee'] instead of 'Set[Employee]'? If so, do
> they have identical meaning?
Yes. There's a FIXME in the PEP source to define forward references
rigorously. See also https://github.com/ambv/typehinting/issues/34
> I can imagine, say, a refactoring tool that didn't understand the full
> Python+MyPy syntax being able to do things with the former that it couldn't
> with the latter. And I think it might look more natural for simple
> recursive types. But those are just vague feelings, so don't take this as a
Well, the most common use case is where you are referencing the current
class (which is in the process of being defined but isn't actually created
until the entire class body is finished). E.g.
def add_left(self, node: 'Node[T]'): ...
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas