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
========================================================================
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.