-
Notifications
You must be signed in to change notification settings - Fork 25
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
Remove Job assert #166
Remove Job assert #166
Conversation
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.
This was just a sanity check, when I started this. I don't see how this could fail, so there should be no harm in removing it.
This looks like a bug in the type checker. I would not remove this assert just because of some buggy type checker. I'm also curious whether Pyright / Pylance are maybe just misconfigured? I hesitate to believe they really get such basic thing wrong. PyCharm gets this correct. |
consider these lines of code
For line 1. both pycharm and pyright complain that Then, after the assert in line 2., in line 3. pycharm infers the type to be Then once one defines a subclass of Job and creates an instance of it,
pyright seems to stick with the From the error in line 1. I assume that the "metaclass with overridden |
One thing we probably should change: class JobSingleton(type):
def __call__(cls, *args, **kwargs): to class JobSingleton(type):
def __call__(cls: Type[T], *args, **kwargs) -> T: (E.g. check mypy doc.) Instead of just using T = TypeVar("T", bound="Job")
You need to differentiate the cases when PyCharm or other type checkers think that But I'm also not sure. Yes, in any case, metaclasses and such logic will confuse/break most/all type checkers. But I still would be hesitant to remove a correct assert check just because some type checker is buggy/broken/incomplete. Can't you add some comment which would make this code ignored by Pyright / Pylance? Most software would ignore it when you add assert isinstance(job, Job) # noqa |
@michelwi could you try if adding I agree with @albertz that keeping the assert would be better, so it would be great if we find a solution to keep it and to solve your problem. And yes: Having more type hinds in Sisyphus would be great and it's of cause hard for any type checker to follow that metaclasses logic... |
It or any other pragma variant does not. But @albertz idea with TypeVar annotation seems to also solve my problem. I will then add the assert again together with the type hints. |
This line breaks my type checker (Pyright / Pylance) and makes it think that all instances of specific jobs are of the parent class
Job
. e.g.The code works, but type checker complains that
sisyphus.Job
has no memberfoo
.Could we remove this line?