Skip to content

Use typing-extensions only on Python < 3.8 #1218

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

Merged
merged 2 commits into from
Apr 24, 2021

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Apr 21, 2021

All necessary attributes are available in the built-in typing module
since Python 3.8. Use typing-extensions only for older versions
of Python, and avoid the unnecessary dep in 3.8+.

@Byron
Copy link
Member

Byron commented Apr 21, 2021

Thanks a lot!

Do you think that it would be possible to use git.compat.typing instead to avoid repeating the logic everywhere where typing is used? I don't know if re-exporting entire modules is possible.

@muggenhor
Copy link
Contributor

I think you meant git.types instead of git.compat.typing? The latter doesn't exist...

@Byron
Copy link
Member

Byron commented Apr 23, 2021

I think this was a clumsy way of asking if there is a less redundant way of specifying the imports. In git.compat types are re-exported based on some logic, so code could rely on importing git.compat.typing alone without repeating any logic.

@muggenhor
Copy link
Contributor

Ah, like this?

# git/compat.py:
if sys.version_info[:2] >= (3, 8):
    import typing
else:
    import typing_extensions as typing

# elsewhere:
from .compat import typing

Unfortunately that has the annoying side effect of not being able to do from git.compat.typing import Literal because git.compat.typing wouldn't be a package/module.

@mgorny mgorny force-pushed the typing-ext branch 2 times, most recently from f6d75c5 to db4bdb4 Compare April 23, 2021 14:17
@mgorny
Copy link
Contributor Author

mgorny commented Apr 23, 2021

@Byron, something like this? Or do you mean entirely replacing from typing ... with from git.compat.typing ...?

All necessary attributes are available in the built-in typing module
since Python 3.8.  Use typing-extensions only for older versions
of Python, and avoid the unnecessary dep in 3.8+.
@Byron Byron added this to the v3.1.16 - Bugfixes milestone Apr 24, 2021
@Byron Byron merged commit 7301771 into gitpython-developers:main Apr 24, 2021
@Byron
Copy link
Member

Byron commented Apr 24, 2021

Thank you very much for this contribution, this looks good to me, and I assume @muggenhor saw nothing that would prevent a merge either.

@mgorny mgorny deleted the typing-ext branch April 24, 2021 06:39
@mgorny
Copy link
Contributor Author

mgorny commented Apr 24, 2021

Thanks! We're removing Python 3.7 support real soon from Gentoo, and so we're going to be one step closer to eliminating typing-extensions as well ;-).

@muggenhor
Copy link
Contributor

Thank you very much for this contribution, this looks good to me, and I assume @muggenhor saw nothing that would prevent a merge either.

Nope, didn't see any obstacles. It looks good!

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

Successfully merging this pull request may close these issues.

3 participants