Runtime detection of PEP 563
Ian Pilcher via Python-list <[email protected]>
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
Given a class object (C), is it possible to *reliably* determine whether the class was compiled with PEP 563 (from __future__ import annotations) enabled? Note that simply looking for the presence of C.__module__.annotations is not really reliable. It will fail in the presence of any of these constructs. from __future__ import annotations as ann or from __future__ import annotations del annotations or annotations = some_entirely_unrelated_thing Testing for the presents of C.__module__.annotations will give a false negative in the first two cases and a false positive in the last case. -- ======================================================================== If your user interface is intuitive in retrospect ... it isn't intuitive ========================================================================