Lightning-AI / lightning-Habana

Lightning support for Intel Habana accelerators.
Apache License 2.0
25 stars 8 forks source link

Update contextmanager to be compatible with Python 3.8 #155

Closed ankitgola005 closed 8 months ago

ankitgola005 commented 9 months ago
Modify typing to support python 3.8 - [ ] Was this discussed/agreed via a Github issue? (no need for typos and docs improvements) - [ ] Did you read the [contributor guideline](https://github.com/Lightning-AI/pytorch-lightning/blob/main/.github/CONTRIBUTING.md), Pull Request section? - [ ] Did you make sure to update the docs? - [ ] Did you write any new necessary tests?

What does this PR do?

Fix support for python 3.8.

Fixes # (issue). in python 3.8: using "_GeneratorContextManager[Any]" as typing gives TypeError: 'ABCMeta' object is not subscriptable

typing in python 3.8 does not recognize _GeneratorContextManager as a type, due to which it gets treated as an iterable, leading to this error. This was changed in Python 3.9 with type aliases. Original code works for Python >= 3.9.

Changed typing to use ContextManager from typing and extend support for python 3.8.

PR review

Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃