-
Notifications
You must be signed in to change notification settings - Fork 44
Clean the code, type annotations and update dependencies #143
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
Conversation
This reverts commit 1920983.
…s in typing module
tap/utils.py
Outdated
def is_literal_type(tp: type) -> bool: | ||
"""Returns whether the type is a literal type.""" | ||
return tp is Literal or getattr(tp, "__origin__", None) is Literal | ||
|
||
def get_origin(tp: type) -> type: | ||
"""Same as typing.get_origin but returns the type itself if the origin is None.""" | ||
origin = typing_get_origin(tp) | ||
return origin if origin is not None else tp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pieces of code that must be added to remove typing_inspect from dependencies. There is little risk of having to modify it for future versions of python since almost everything is done in the typing module
What's the story here? |
I apologize for the waste of time. I realized there were too many conflicts with other pull requests. It seems easier to me to make a (much) cleaner one later. The goals remain: update the < 3.8 Python code and add more precise type hints. |
I see. Sorry for the conflicts! I think making a few smaller PRs will make it easier to merge! Thanks! |
Some code must have been added before Python 3.8. We can put this version to good use. These fixes do not modify the runtime in any way.
Changes:
typing.Protocol
andtyping.TypedDict
instead of bare dict, callable or typesI think it is possible to go much further in type annotation (e.g. by annotating some methods with *args and **kwargs). But for this, typing-extensions must be added as a dependency.
I thought for a long time that using
from __future__ import annotations
to usedict[str | int, int] | List[str |int]
instead ofUnion[Dict[Union[str, int], int], List[Union[str, int]]
would be a good idea, but the package itself does not support this syntax so it would only be an additional source of bugs.