Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast is used in internal.io_handling but not imported if typing is not present #166

Closed
mattsb42-aws opened this issue Oct 14, 2019 · 1 comment · Fixed by #167
Closed
Labels

Comments

@mattsb42-aws
Copy link
Member

As with all of our other modules, in internal.io_handling we catch all imports from typing because of issues with CPython 3.5.0 and 3.5.1.

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import cast, Dict, IO, List, Type, Union # noqa pylint: disable=unused-import
from aws_encryption_sdk_cli.internal.mypy_types import SOURCE, STREAM_KWARGS # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass

In 1.1.6, we removed the dependency on typingbecause I had thought that we only used imports from typing in our Python-2-compatible typehints.

However, in internal.io_handling, we use typing.cast.

stream_args=stream_args, source=cast(IO, source), destination_writer=destination_writer

This only does anything when the file is being processed by mypy or a similar analyzer, so a quick fix for this is for us to just assign a no-op lambda to cast in the import catch statement.

However, I am concerned that our CI did not catch this...I would like to find out what happened there too.

@mattsb42-aws
Copy link
Member Author

mattsb42-aws commented Oct 15, 2019

I am unable to replicate the error that was reported, but in light of this and how we are actually using the typing module, I think that the correct solution here is to simply remove the install dependency. This will require us to add a no-op definition for cast in the modules that we use it, as well as for any of the types that we include in the calls to cast.

ex:

except ImportError:
    cast = lambda typ, val: val
    IO = Tuple = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant