Closed iperov closed 1 year ago
Note that I am not working on pytypes at the moment. That said, this does look more like as VSCode issue; there is a helper pytypes.util._actualfunc
that retrieves the backing function if they fail to retrieve it their way. Since it is impossible to tell what VSCode is actually doing, that cannot be fixed in pytypes.
For pytypes issues, please provide the stacktrace (place pytypes.clean_traceback = False
at top to reveal pytypes-internal part of the stack trace) and a reproducible example.
Also, you can avoid decorator issues by using profiler mode.
look more like as VSCode issue
i don't think so.
this solution works
from typing import TypeVar
import pytypes
T = TypeVar('T')
def typechecked(func : T) -> T:
return pytypes.typechecked(func)
also, can you recommend a similar library that works with Generic?
this solution works
For some reason VSCode tries to determine the arg types of a function. That solution likely won't help it access the original types. Anyway, if it silences the error, your adjustment is a simple enough fix.
Changing the typechecked
signature in typechecker.py
should do the same trick. If it is as simple as that I can make that change. Can you confirm that making the change in typechecker.py
fixes it for you? (changing line 1007 from def typechecked(memb):
to def typechecked(memb: T)->T:
)
I am not aware of any other lib that works with Generic, but I might not have an up to date picture. Maintenance of such a feature is immensely painful because of rapid changes in the typing module. pytypes only works for Pythons up to 3.8 as of this writing.
the bug reproduced in python 3.8.10
def typechecked(memb: T)->T:)
unfortunately does not work. May be the bug in vscode.
immensely painful because of rapid changes in the typing module
I understand, that's sad. It seems only your library support Generic type checking.
by the way, decorator should return func wrapper
def typechecked(memb : T) -> T:
if not pytypes.checking_enabled:
return memb
I think such code confuses hint evaluator
(deleted spam)
unable to determine func signature in hint
with usual decorator all fine