-
Notifications
You must be signed in to change notification settings - Fork 169
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
Issue with Callable type for < Python 3.9 #293
Comments
@carljm can you please guide me here on how to proceed? Please let me know if you require more information on this, I would be happy to work on this |
Hi @sagarbadiyani -- unfortunately it may be up to a few weeks before I have time to dig into this issue and recommend what I think is the best approach; it looks like it's a bit subtle. If you are able to reach a solution sooner that you are confident is the correct one, I can try to find time to look at a PR. |
Sure, @carljm, I will try to solutionize this. |
@sagarbadiyani I've encountered the same issue on Python 3.7.3. - if elem_type_dicts is not None and is_generic(typ):
+ if elem_type_dicts and is_generic(typ):
elem_types = tuple(type_from_dict(e) for e in elem_type_dicts)
# mypy complains that a value of type `type` isn't indexable. That's
# true, but we know typ is a subtype that is indexable. Even checking
# with hasattr(typ, '__getitem__') doesn't help
+ if elem_types:
- typ = typ[elem_types] # type: ignore[index]
+ typ = typ[elem_types] # type: ignore[index] |
This issue is reproducible in Python 3.8 but not reproducible in Python 3.10
Consider a file
some/module.py
Consider another file
myscript.py
Run
monkeytype run myscript.py
Then run
monkeytype stub some.module
This throws an error
As we can see, the input type of
b
inzzz
is Dict[str, Callable]On trying to serialize the trace, I found that in Python 3.8, the arg type for
b
wasWhile in 3.10, the arg type for
b
wasNotice an extra
"elem_types": [],
in Py38Upon digging further I found that this is because
type_to_dict(typing.Callable)
returns{'module': 'typing', 'qualname': 'Callable'}
in Py310,but
{"elem_types": [], 'module': 'typing', 'qualname': 'Callable'}
in Py38Should we consider adding an explicit check for
elem_types
being[]
at https://github.com/carljm/MonkeyType/blob/ff7cc071971cc33e1b3e29df1fbbef85c7fbf89a/monkeytype/encoding.py#L83 ?(
d["elem_types"] = [type_to_dict(t) for t in elem_types]
)If yes, I would be happy to raise a PR for this.
Suggested change
But I am not confident of this suggested change since it might cause regression given
elem_types
has been explicitly set to()
just 1 line above, in which case, shouldCallable
be handled explicitly?Or should this be handled while stubbing in
encoding.py
indef type_from_dict()
atThe text was updated successfully, but these errors were encountered: