[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2022-03-20 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +AlexWaygood, JelleZijlstra ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2022-03-20 Thread Anton Agestam
Anton Agestam added the comment: As a consumer of `get_type_hints()` I think it'd be valuable to even have partially resolved types. My use case is that I provide an `Annotated` alias with a marker, and all I care about when inspecting user type hints is whether or not the arguments of an

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Larry Hastings
Larry Hastings added the comment: I admit I hadn't looked that closely at Jelle's PR. You're right, its effects on code size should be minimal. If I'm reading it correctly, Jelle's PR would suppress NameError by replacing the failed value with a new "AnnotationName" object. It wouldn't

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Guido van Rossum
Guido van Rossum added the comment: I thought Jelle’s solution would avoid code bloat — a dedicated opcode. It can do whatever is decided. -- nosy: +Guido.van.Rossum ___ Python tracker

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Larry Hastings
Larry Hastings added the comment: It would also cause the code generated for the annotations function to balloon--the calculation of every value would have to be wrapped in a try/except, and for what I assume is an obscure use case. I'm already getting some pushback on the code generated

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Guido van Rossum
Guido van Rossum added the comment: If the NameError were to leave behind a marker wrapping the string, that might allow the best of both worlds -- errors don't pass *silently* (an error value is returned) and you can still inspect the other annotations. --

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Larry Hastings
Larry Hastings added the comment: > Hey Larry, it would seem that PEP 649 as currently specified would make it > impossible to access annotations via the inspect module in cases where > x.__annotations__ raises (because one of the annotations references an > undefined variable). That's

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-04-16 Thread Guido van Rossum
Guido van Rossum added the comment: Hey Larry, it would seem that PEP 649 as currently specified would make it impossible to access annotations via the inspect module in cases where x.__annotations__ raises (because one of the annotations references an undefined variable). I really think

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-15 Thread Florian Bruhin
Florian Bruhin added the comment: Ah, I wasn't aware of that, thanks for the pointer! So what inspect does internally is: def _get_type_hints(func, **kwargs): try: return typing.get_type_hints(func, **kwargs) except Exception: # First, try to use

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-15 Thread Ken Jin
Ken Jin added the comment: @Florian, IIUC inspect.signature auto-resolves string annotations to typing.ForwardRef internally from 3.10 onwards. It's mentioned in the what's new for PEP 563

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-15 Thread Guido van Rossum
Guido van Rossum added the comment: Please open a separate issue for that. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-15 Thread Florian Bruhin
Florian Bruhin added the comment: Fair points. As an aside, I'm also wondering how inspect.Parameter.annotation should interact with the changes in Python 3.10? That used to be the canonical way (as far as I'm aware) of getting a single argument's type annotation (other than getting it

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-12 Thread Guido van Rossum
Guido van Rossum added the comment: If we add a new flag to ignore errors it's difficult to write code that works in 3.9 as well. And given the use case I have doubts that "Errors should never pass silently" is really the right Zen line to focus on. I'd rather go for "Simple is better than

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-12 Thread Florian Bruhin
Florian Bruhin added the comment: I suppose returning the string unchanged would work as well. However, "Errors should never pass silently." :) Perhaps that with a ignore_nameerror=True or switch or so would work? -- ___ Python tracker

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-10 Thread Guido van Rossum
Guido van Rossum added the comment: Maybe return the original string? -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-10 Thread Ken Jin
Change by Ken Jin : -- nosy: +kj ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-10 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

2021-03-10 Thread Florian Bruhin
New submission from Florian Bruhin : Consider a file such as: # from __future__ import annotations from typing import TYPE_CHECKING, Union, get_type_hints if TYPE_CHECKING: import types def fun(a: 'types.SimpleNamespace', b: Union[int, str]): pass