This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mjpieters
Recipients mjpieters
Date 2016-03-03.18:07:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1457028467.36.0.208660584048.issue26477@psf.upfronthosting.co.za>
In-reply-to
Content
Forward references to a module can fail, if the module doesn't yet have the required object. The "forward references" section names circular dependencies as one use for forward references, but the following example fails:

$ cat test/__init__.py
from .a import A
from .b import B
$ cat test/a.py
import typing
from . import b

class A:
    def foo(self: 'A', bar: typing.Union['b.B', None]):
        pass
$ cat test/b.py
import typing
from . import a

class B:
    def spam(self: 'B', eggs: typing.Union['a.A', None]):
        pass
$  bin/python -c 'import test'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mjpieters/Development/venvs/stackoverflow-3.5/test/__init__.py", line 1, in <module>
    from .a import A
  File "/Users/mjpieters/Development/venvs/stackoverflow-3.5/test/a.py", line 2, in <module>
    from . import b
  File "/Users/mjpieters/Development/venvs/stackoverflow-3.5/test/b.py", line 4, in <module>
    class B:
  File "/Users/mjpieters/Development/venvs/stackoverflow-3.5/test/b.py", line 5, in B
    def spam(self: 'B', eggs: typing.Union['a.A', None]):
  File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/typing.py", line 537, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/typing.py", line 494, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/typing.py", line 494, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/typing.py", line 185, in __subclasscheck__
    self._eval_type(globalns, localns)
  File "/Users/mjpieters/Development/Library/buildout.python/parts/opt/lib/python3.5/typing.py", line 172, in _eval_type
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
AttributeError: module 'test.a' has no attribute 'A'

The forward reference test fails because only NameError exceptions are caught, not AttributeError exceptions.
History
Date User Action Args
2016-03-03 18:07:47mjpieterssetrecipients: + mjpieters
2016-03-03 18:07:47mjpieterssetmessageid: <1457028467.36.0.208660584048.issue26477@psf.upfronthosting.co.za>
2016-03-03 18:07:47mjpieterslinkissue26477 messages
2016-03-03 18:07:46mjpieterscreate