pytypes icon indicating copy to clipboard operation
pytypes copied to clipboard

Allow one to specify module to get_type_hints

Open mitar opened this issue 6 years ago • 2 comments

Currently it is trying to guess the module, but this is not always possible. For example, it does not work for me if I call get_type_hints while the module is being defined and module does not yet exist.

A workaround for me is that currently I set im_class attribute on the function I want to get type hints for, but I think it might be cleaner if there would be an optional argument get_type_hints.

mitar avatar Dec 19 '17 03:12 mitar

Using get_type_hints within a module while that same module is being defined sounds like evil zone (but honestly, pytypes already needs to navigate evil zone from time to time^^). So, if such an additional parameter helps to solve some difficult situations it's fine for me.

However, is it actually the right solution to provide module as a new parameter? Wouldn't it be better to directly provide the class? I suppose it boils down to this call where the module would be required. _get_types already provides an optional class parameter that would avoid that entire branch. If it would be sufficient to provide the class, adding this parameter would be as easy as forward it through _get_type_hints, get_types (should stay compatible to get_type_hints anyway) and _get_types.

Stewori avatar Dec 24 '17 04:12 Stewori

Oh, I think class would be perfectly fine. I do not remember why I proposes to pass a module. Currently I am setting im_class anyway, which is a class. :-)

So yes, class would be great.

mitar avatar Dec 24 '17 05:12 mitar