-
Notifications
You must be signed in to change notification settings - Fork 848
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
If I have a variable of known type and want that name to now reference an object of another type, pylance complains. E.g.:
def parse_int(x: str):
x = int(x)
return x
gives
Expression of type "int" cannot be assigned to declared type "str"
"int" is incompatible with "str" Pylance (reportGeneralTypeIssues)
I can see how this would sometimes be useful to catch, but I would personally prefer for this not to be seen as an issue. I did try to explicitly declare the type the second time, to show that I'm intentionally changing it, but that just gives a different error:
def parse_int(x: str):
x: int = int(x)
return x
Parameter declaration "x" is obscured by a declaration of the same name Pylance (reportGeneralTypeIssues)
I believe mypy supports an option to allow such type changes; could support for this be added to pylance?
(I'm not sure if this request should be on pylance or pyright; let me know if I'm in the wrong place or if there's already a configuration option I can change somewhere to achieve this)
saaketp, nurockplayer, Jaakkonen, d-k-bo, neumannjan and 12 more
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request