Diagnostics to disable "reportUnknownArgumentType" for lambdas only in complex scenarios #2621
Replies: 2 comments
-
You are correct that Python unfortunately doesn't provide any syntax for annotating the input parameters for a lambda, but you can provide an annotation outside of the lambda that provides sufficient context. I can provide more details if you supply a working self-contained sample. The sample you've provided above has several errors and omissions. |
Beta Was this translation helpful? Give feedback.
-
The screenshot wasn't an example, it was intended to showcase how verbose and noisy it becomes. import struct
import binascii
b = b'\x01\x00\x00\x00'
unpack_int = struct.Struct('<I').unpack
my_map = dict(numValues = {'reader': lambda x: unpack_int(x)[0]})
for key, value in my_map.items():
f = value['reader']
value['value'] = f(b[0:4])
print(my_map) I figured you can just do:
but the thing is, down the line I assign new keys with different value types so now I have:
but even this wont sole the issue when I get two keys from value that are ints but they cant be summed: I still insist that the feature in question would be useful to avoid needless noise. Perhaps implemented in this way as described here: |
Beta Was this translation helpful? Give feedback.
-
Consider the following:
If you have
reportUnknownArgumentType
set to anything abovenone
it will report this. Problem is, as far as I know, in that particular setup, you cannot annotate lambda properly with type hints. But if you disablereportUnknownArgumentType
you will lose the ability completely.I don't think that's a fair trade and I think adding extra diagnostics option is lesser evil and less crumblesome than plaguing your code with
#type: ignore
all the way:Beta Was this translation helpful? Give feedback.
All reactions