You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello folks. I'm working on a plugin that uses get_dynamic_class_hook to construct type constructors (TypeInfo) and class definitions (ClassDef) that don't exist in a module. I add these definitions to a MypyFile. Finally, I add this MypyFile to the modules dictionary provided by the SemanticAnalyzerPluginInterface API to convince mypy of my "fake" module.
This works wonderfully until a second run of my plugin when the .mypy_cache has been constructed. Before semantic analysis, mypy seems to be trying to read my fake module, because in the cache names in real modules have a target that refers to the fake module. For instance,
The stacktrace is below. mypy fails to resolve FakeModule.SomeType because FakeModule doesn't exist in its modules dictionary. I don't think my use of get_dynamic_class_hook is unusual, so I think there's a hole in my understanding of this hook.
Hi ljluestc, thanks for your help! Your excerpt is similar to the approach I'm currently taking, except that we may be running different mypy versions because your MypyFile constructor looks different than mine. I'm on mypy 1.10.0.
I'm not sure your excerpt solves my issue though, because looking at my stacktrace control is never transferred to the plugin before mypy crashes. It doesn't look like mypy reaches its semantic analysis stage and my_dynamic_class_hook (in your case) never fires.
Hello folks. I'm working on a plugin that uses
get_dynamic_class_hook
to construct type constructors (TypeInfo
) and class definitions (ClassDef
) that don't exist in a module. I add these definitions to aMypyFile
. Finally, I add thisMypyFile
to themodules
dictionary provided by theSemanticAnalyzerPluginInterface
API to convincemypy
of my "fake" module.This works wonderfully until a second run of my plugin when the
.mypy_cache
has been constructed. Before semantic analysis,mypy
seems to be trying to read my fake module, because in the cache names in real modules have atarget
that refers to the fake module. For instance,The stacktrace is below.
mypy
fails to resolveFakeModule.SomeType
becauseFakeModule
doesn't exist in itsmodules
dictionary. I don't think my use ofget_dynamic_class_hook
is unusual, so I think there's a hole in my understanding of this hook.The text was updated successfully, but these errors were encountered: