- Notifications
You must be signed in to change notification settings - Fork220
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 seehere, 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. |
BetaWas this translation helpful?Give feedback.
All reactions
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'sdatetime
moduleimports 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 beconfigured to introspect specific extension modules by actually executing them using theextension_modules
option.
So to fix this, you can either add this to your project's.ropeproject/config.py
file:
defset_prefs(prefs):prefs["extension_modules"]= ["_datetime"]
or this to …
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? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Any advice on this? Is this something expected? Should i maybe configure something on my end? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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 beconfigured to introspect specific extension modules by actually executing them using the So to fix this, you can either add this to your project's defset_prefs(prefs):prefs["extension_modules"]= ["_datetime"] or this to your project's [tool.rope]extension_modules = ['_datetime'] |
BetaWas this translation helpful?Give feedback.
All reactions
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Wow!! Really thank you@smheidrich for the thorough explanation about what happens and how to solve it. Appreciate you taking the time and effort to take a look into this 😄 |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1