ITADN

False positive passing self to function in other file expecting object of class type

#1800Openethanbb 创建于 2026-05-11
awaiting response
E
ethanbbcommented
### Description I have code that looks like the following: caiman_analysis.py: ```python from . import foo class SessionAnalysis: ... def print(self): foo.print_sessinfo(self) ``` foo.py: ```python from . import caiman_analysis as cma def print_sessinfo(x: 'cma.SessionAnalysis'): print(x) ``` The `self` argument to `print_sessinfo` is highlighted with the message: ``` Argument of type "Self@SessionAnalysis" cannot be assigned to parameter "x" of type "SessionAnalysis" in function "do_cnmf_gridsearch" "SessionAnalysis*" is not assignable to "SessionAnalysis"basedpyright[reportArgumentType](https://docs.basedpyright.com/v1.39.4/configuration/config-files/#reportArgumentType) ``` There's another instance where I'm passing `self` to another external function that expects an instance of this class, and I get the same error. Oddly, though, I don't get it when the function is in the same file (and annotated with `SessionAnalysis` or `'SessionAnalysis'` rather than `'cma.SessionAnalysis'`). Thus I tried to replicate it in the playground, but there's no error here: https://basedpyright.com/?typeCheckingMode=all&code=MYGwhgzhAEBiD28BcAoa7oBMCmAzaAHgBQTYi4CUqGN0ADgE4CWAdgC4D6uiJZlKKHPkatO3eEVxJoAcgTwZVNBhHtJFIA I'm using version 1.39.4 in the VS code extension.
1 条评论