-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add fix for typing #65
Conversation
68958df
to
3230c1f
Compare
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 PR has the other changes lumped in, so those should be merged first. I'd also like to see a deterministic __hash__
implementation rather than randint
import_tracker/lazy_import_errors.py
Outdated
self._raise() | ||
if not _is_import_time(): | ||
self._raise() | ||
return randint(0, 100000000) |
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.
I don't like using randint
here. How about id(self)
? Nondeterminism scares me.
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.
Ah yes. That would be better.. Will change this
import_tracker/lazy_import_errors.py
Outdated
@@ -530,3 +544,9 @@ def _get_non_import_modules(cls): | |||
for frame in cls._FrameGenerator() | |||
), | |||
) | |||
|
|||
|
|||
def _is_import_time(): |
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.
I think this will be caught in the other PR, but this needs a docstring and type hint
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.
yep, will add that. This PR would need rebasing after the other one gets merged
3230c1f
to
49a0320
Compare
Signed-off-by: Gaurav-Kumbhat <[email protected]>
Signed-off-by: Gaurav-Kumbhat <[email protected]>
Signed-off-by: Gaurav-Kumbhat <[email protected]>
49a0320
to
e94db07
Compare
@@ -244,7 +242,8 @@ def __delitem__(self, *_, **__): | |||
self._raise() | |||
|
|||
def __eq__(self, *_, **__): | |||
self._raise() | |||
if not _is_import_time(): |
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 should return a bool
if _is_import_time
is true
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.
Ah yes, good point! Like the function __eq__
would need to return bool?
I guess currently it would return None
which would be falsey, so may be we should return False
if _is_import_time
is True
?
Signed-off-by: Gaurav-Kumbhat <[email protected]>
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.
Looks good!
Changes
based on #64
Scenarios
Dict[foo, str]
Union[foo, str]
Typing is another one of the operations that happens at the import time.
In both above scenarios, a hashing is performed under the hood in python that tries to make a unique combination of the presented types. Since we are replacing it with lazy module, without this fix, we are raising error for
__hash__
function, and thus the typing at import time, throws error.