-
Notifications
You must be signed in to change notification settings - Fork 29k
Improve type annotations in many places #6220
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
… data.processors.utils.py, trainer.py
From what I can see, test failures are because of the usage of The |
I'd avoid adding a new dependency or pinning us on python 3.8. I'd also avoid using For instance, the first:
could be written like this in the main definition:
and then the body of the function can be updated. |
Sounds good. I'll get around to removing usages of |
Thinking a bit more about this, if you really need some types in |
The types in this PR that need
DataClass = NewType("DataClass", Any)
DataClassType = NewType("DataClassType", Any) with class DataClassProtocol(Protocol):
def __init__(self, *args: Any, **kwargs: Any) -> None: pass
# And DataClassType would be replaced with Type[DataClassProtocol] in the rest of the code The benefit of this is that I really like static type checking, so I'm for adding |
Personally I'd love to use For the |
Slightly off topic, but @davidatbu do you have experience on Pyright vs. mypy? (in particular in the context of vscode) I've been wanting to dig in for a long time. |
Yes, this won't lead to inference of the actual dataclass passed in the current mypy implementation(it might if mypy ever supports variadic generics, and we make
I've used only mypy so far. (And I find it so helpful that I'm willing to create PRs for type annotation :) )Also, I use Vim with plugins, so wouldn't be able to comment on the vscode aspect either. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@davidatbu I noticed you referenced python/typing#193 on variadic generics in this thread. Heads up that we've been working on a draft of a PEP for this in PEP 646. If this is something you still care about, take a read and let us know any feedback in this thread in typing-sig. Thanks! |
DataProcessor
inherit fromabc.ABC
. Along with that, the methods that previously hadraise NotImplementedError()
are now decorated by@abc.abstractmethod
. This change was motivated by the fact that the static analyzers like mypy can correctly identify unimplemented methods in subclasses.This PR is a result of a question on post on the forum.
Closes #6118 too.