Userdefined builtins or globals

Answered

I'm writing plugins for Plex app. It uses Python 2.7 and has Framework for plugins. Plugins are executed in sandbox using eval with environment, where all api functions are predefined. So i don't need to import anything from Framework package inside plugin code.

I tried to use stubs files (pyi extension), but when i select anything from code completion - this stub files are imported in code, i.e.:

#plex.pyi
from Framework import api
Log = api.LogKit()
#__ini__.py
from plex import Log
Log.Debug(zzz)

It is possible to use stubs files without importing? Or how can i define some builtins/global variables?

1
3 comments

That's correct, .pyi stubs do not allow you to declare that some symbols are provided by the runtime and don't need to be explicitly imported, i.e. extend the interface of the standard builtins.pyi/__builtin__.pyi modules without altering them directly. 

I'm afraid, the best thing you can do about it right now is to manually list the corresponding symbols in the whitelist of "Unresolved references" inspection settings. It won't give any code insight for them, but at least suppress respective warnings in the editor.

0

Bummer! I was literally *just* about to post asking the same question.

It would be incredible if this could somehow be added as a function of PyCharm. I have a series of dummy imports in my files that I use if I really need code-completion, otherwise, yeah, I just whitelist the unresolved references and go about my business.

Still, being able to define a custom project or something that assumes the Plex methods are just "there" would be amazing. I can't tell you how many people I could point to PyCharm then...

0

I've created a feature request describing one possible way to handle such extra built-in names. Please follow it to be notified about the progress and related discussions.

0

Please sign in to leave a comment.