Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Regarding auto-import feature and datetime#540

Answeredbysmheidrich
dpetka2001 asked this question inQ&A
Discussion options

I installedpython3 -m pip install python-lsp-server andpython3 -m pip install "python-lsp-server[rope]" in my virtual environment to test out thepython-lsp-server. I use Neovim and have configuredlspconfig as follows

pylsp= {settings= {pylsp= {plugins= {rope_autoimport= {enabled=true,                },              },            },          },        },

When I open a python file in my virtual environment and typefloor then I get completion for auto-importingmath and when typingsleep I get completion for auto-importingsleep. However, when I typedatetime I only get completion for auto-importingfrom xmlrpc.client import DateTime.

Am I maybe missing some configuration option to enable additional module preloading with pylsp and rope? From what I can seehere, I believe thatdatetime module should be preloaded? Or maybe I have no idea what I'm talking about.

Please excuse my ignorance as I'm still new to programming and grabbed Python as my first language to start. If I doimport datetime, then I get completion about the modules that are available.

Appreciate any help. Thanks in advance.

You must be logged in to vote

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

Comment options

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?

You must be logged in to vote
1 reply
@dpetka2001
Comment options

Any advice on this? Is this something expected? Should i maybe configure something on my end?

Comment options

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 your project'spyproject.toml or globalpytool.toml:

[tool.rope]extension_modules = ['_datetime']
You must be logged in to vote
0 replies
Answer selected bydpetka2001
Comment options

P.S. Can you please change the title to something more specific so others can find this discussion more easily? E.g.

Regarding auto-import feature and datetime

I had the same issue and I'm sure there will be more after me.

You must be logged in to vote
1 reply
@dpetka2001
Comment options

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 😄

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@dpetka2001@ccordoba12@smheidrich

[8]ページ先頭

©2009-2025 Movatter.jp