Azure / msrest-for-python

The runtime library "msrest" for AutoRest generated Python clients.
MIT License
41 stars 64 forks source link

Import error when importing msrest with typing.TYPE_CHECKING = True #128

Closed adamtheturtle closed 5 years ago

adamtheturtle commented 5 years ago

Install msrest:

(msrest) Adam@MacBook-Pro ~/Desktop> pip install --upgrade msrest
...
(msrest) Adam@MacBook-Pro ~/Desktop> pip freeze
certifi==2018.10.15
chardet==3.0.4
idna==2.7
isodate==0.6.0
msrest==0.6.1
oauthlib==2.1.0
requests==2.20.1
requests-oauthlib==1.0.0
six==1.11.0
urllib3==1.24.1
(msrest) Adam@MacBook-Pro ~/Desktop> python --version
Python 3.7.0

Attempt to import msrest with typing.TYPE_CHECKING = True:

(msrest) Adam@MacBook-Pro ~/Desktop> python -c 'import typing; typing.TYPE_CHECKING = True; import msrest'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/__init__.py", line 28, in <module>
    from .configuration import Configuration
  File "/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/configuration.py", line 37, in <module>
    from .exceptions import raise_with_traceback
  File "/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/exceptions.py", line 34, in <module>
    from msrest.serialization import Deserializer
  File "/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/serialization.py", line 46, in <module>
    from .pipeline.universal import RawDeserializer
  File "/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/pipeline/__init__.py", line 54, in <module>
    from ..exceptions import ClientRequestError, raise_with_traceback
ImportError: cannot import name 'ClientRequestError' from 'msrest.exceptions' (/Users/Adam/.virtualenvs/msrest/lib/python3.7/site-packages/msrest/exceptions.py)

My use case is that I am trying to generate documentation for code which uses msrest. I am using https://github.com/agronholm/sphinx-autodoc-typehints. This sets typing.TYPE_CHECKING = True.

The most recent version of msrest for which this works is 0.4.29.

lmazuel commented 5 years ago

I reproduce it, I just don't understand why mypy doesn't complain, since it's setting TYPE_CHECKING as well. See what I can do to fix it.

lmazuel commented 5 years ago

PR merged, to be released in 0.6.2