Regarding auto-import feature and datetime #540
-
I installed pylsp = {
settings = {
pylsp = {
plugins = {
rope_autoimport = {
enabled = true,
},
},
},
},
}, When I open a python file in my virtual environment and type Am I maybe missing some configuration option to enable additional module preloading with pylsp and rope? From what I can see here, I believe that Please excuse my ignorance as I'm still new to programming and grabbed Python as my first language to start. If I do Appreciate any help. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hey @dpetka2001, thanks for reporting. I'm not sure what's happening because I don't use this functionality. @tkrabel, any ideas about this one? |
Beta Was this translation helpful? Give feedback.
-
ExplanationThis is a limitation of Rope: By default, it uses static analysis of Python source code to find out which names are available for import, but this can't work for C extension modules which don't have any Python source code. Python's How to fixRope can be configured to introspect specific extension modules by actually executing them using the So to fix this, you can either add this to your project's def set_prefs(prefs):
prefs["extension_modules"] = ["_datetime"] or this to your project's [tool.rope]
extension_modules = ['_datetime'] |
Beta Was this translation helpful? Give feedback.
-
P.S. Can you please change the title to something more specific so others can find this discussion more easily? E.g.
I had the same issue and I'm sure there will be more after me. |
Beta Was this translation helpful? Give feedback.
Explanation
This is a limitation of Rope: By default, it uses static analysis of Python source code to find out which names are available for import, but this can't work for C extension modules which don't have any Python source code.
Python's
datetime
module imports its actual contents from a C extension module named_datetime
, so Rope can't find out about them using this default approach.How to fix
Rope can be configured to introspect specific extension modules by actually executing them using the
extension_modules
option.So to fix this, you can either add this to your project's
.ropeproject/config.py
file:or this to …