What are fallback completions in Spyder? - python

There is an option in the Spyder IDE (Tools->Preferences->Completion and linting->Advanced) to activate fallback completions:
What are fallback completions, how are they supposed to work and help? I have googled it and not found a description.
Note this question was inspired by this question complaining (implicitly) about fallback completions: How to disable keyword / text suggestion in Spyder 4?
There, it isn't really explained what this feature is supposed to be, how it is supposed to work, but basically how to turn it off using the above interface. I am not trying to turn them off I am trying to find out what exactly are fallback completions, and how are they different from other types of completion going on?

(Spyder maintainer here) Fallback completions are those completions provided by the tokens present in the file (i.e. any word on it, be it code, comments or strings), plus some Python builtin keywords (e.g. finally).

Related

Mandatory member function arguments - to much expectations from Python compiler and/or PyDev

I've created the class CustomErr (inherits from Python's Exception) long time ago and I'm using it on a few hundred places in code. It has a member method which is declared with def logErr(self).
After some time I found that this function should have mandatory keyword argument logger, so I've changed declaration of the function to def logErr(self, *, logger).
After this change I've expected a few hundred compiler errors, or at least warnings (so it will be easy for me to make needed changes), but it didn't happen - there is not a single error reported. I only get runtime exception when this function is called.
Did I expect too much from Python compiler and/or my working IDE (I'm using Eclipse with PyDev 8.1, Python 3.8.7)?
Do I need a Python linter ?
PyDev by default doesn't really provide this checking -- it does have code-analysis builtin, but it focuses on being very fast and on having very few false positives and it doesn't really delve in the type-checking territory.
In PyDev the recommended way to work with this is through an external linter or type-checker.
PyDev has integrations with Flake8, Mypy and PyLint (the related configuration in the preferences is under PyDev > Editor > Code Analysis > Flake8/Mypy/PyLint).
If you're using type hints in your code, enabling Mypy is probably a no-brainer and actually required to make use of such typing for code analysis in PyDev... out of the box PyDev will use that info for code-completion, but there aren't plans to add it for code analysis as I'm a bit worried about duplicating what's already available in Mypy anyways and I don't see much positives in having yet another type checker.
PyLint may also be interesting as it does get some interesting errors (but in my experience it usually also has a higher false positive ratio, so, it may need to be tweaked a bit more) -- if you don't use type-hints (and thus wouldn't really get much from Mypy), I think that using PyLint is interesting as it does try to cover more ground than PyDev.
As a note, if you're not using type-checking/MyPy, what you want is probably not achievable with 100% certainty by any tool because it's difficult to find out that something as parameter.logErr means the logErr in your CustomErr and not really some other logErr somewhere else (because discovering that the type of parameter is CustomErr is really hard).
p.s.: automatically running the type-checker/linter is done for each file as you save it, but you can also run it for the whole project by right-clicking a project/file and then selecting PyDev > Code Analysis.

How do I display function arguments in ipython qtconsole?

I'm using IPython qtconsole under windows 7, and when I first write a method name and type the bracket, a popup shows method parameters.
What is the way to display that popup explicitly, once it has disappeared? This is pretty common 'show method parameters' shortcut that I'm talking about, but I've failed to find the shortcut to it after an embarrassing amount of google searches.
In Spyder, try View - Panes - Object inspector. Then type the full name of the function.
I would highly recommend relying on the Python Library Reference rather than any in-IDE tools, at least for functions and classes that are in the standard library. For objects outside those libraries however... it looks like you can type object_name followed by a question mark, that is, object_name?, to get a list of informative details about the object. (Since everything is an object, this presumably includes functions.)
For your specific question, it looks, from the iPython docs, like the TAB key is what you're looking for, but somehow I doubt you haven't already tried that.

What does wrapping a string in N_() do in Python-Fu?

<TL;DR>
It's used for internationalization in the GTK+, GIMP's GUI Toolkit. The link to the documentation is: N_()
</TL;DR>
I'm working on Python-Fu and frequently see strings surrounded by N_(), as in: N_("Some random string").
Yet in another plug-in, the N_() wont be there and "Some random string" works just fine.
So what gives? I've searched around but didn't really find anything on this. A little help from a python expert would be greatly appreciated as I'm fairly new to it. Thanks!
<< Edit >>
This is a python plug-in registration function call for GIMP 2.8. It is required in each plugin and it registers the plugin with the GUI, showing up in the menuing system where you dictate in the 12th argument.
This is not to be confused with an earlier version of GIMP's parameter order, or Script-Fu, which is based on Scheme and so is unfortunately ugly as sin.
register(
"omnicyde_btn_metal_ring",
N_("Badass Glossy Metal Ring Button"),
"This is going to be so incredibly sweet",
"Omnicyde",
"Omnicyde",
"2014",
"_BtnMetalRing",
"",
[],
[],
btn_metal_ring,
menu="<Toolbox>/Omnicyde/Buttons",
domain=("gimp20-python", gimp.locale_directory)
)
So, in some plugins there will be a N_() wrapping a string, and in some there won't for the same string in the argument list. Both versions work..
I figured it was a python core construct or something, as I'm kinda new to it. Then again, I'm new to Python-Fu as well. It's equally possible this is some GIMP thing, or even Python-Fu..
It is as hinted in the comments. N_ is an i10n macro defined in gi18n.h. gi18n uses the gettext library.
http://opensource.apple.com/source/ChatServer/ChatServer-37.1/libraries/glib-2.4.5/glib/gi18n.h
As for the gettext_noop you can see its uses at
http://www.gnu.org/software/gettext/manual/html_node/Special-cases.html

using emacs CEDET completion for python

In default installation of cedet-1.0 completion can only track global scope symbols in current file. This is not much differs from built-in completion functions (dabbrev-expand or hippie-expand).
It can complete symbols from neither imported modules, nor class properties.
Not saying it cannot handle 'self'.
Is it possible to tweak semantic to do the things?
P.S.
ECB code browser sucesfully sees all imports/base classess and stuff.
It is symbol completion workd incorrectly, or not properly set up.
CEDET support for each language is slightly different. In the case of python, the 1.0 release for CEDET hadn't been configured to convert a python import into a file-name. In addition, 'self' is similar to 'this' in c++, which needs to be added by completion logic since it isn't declared. These two features were added to the bzr repository in January of this year. I am not a python programmer, but I recall reports that this fixed a range of the most basic features of smart completion so that symbols from imported libraries works. There was also new code in bzr for python system paths.
Thus, I recommend downloading CEDET from bzr to get these features to see if it now does what you would expect for smart completion.

Vim Python omni-completion failing to work on system modules

I'm noticing that even for system modules, code completion doesn't work too well.
For example, if I have a simple file that does:
import re
p = re.compile(pattern)
m = p.search(line)
If I type p., I don't get completion for methods I'd expect to see (I don't see search() for example, but I do see others, such as func_closure(), func_code()).
If I type m., I don't get any completion what so ever (I'd expect .groups(), in this case).
This doesn't seem to affect all modules.. Has any one seen this behaviour and knows how to correct it?
I'm running Vim 7.2 on WinXP, with the latest pythoncomplete.vim from vim.org (0.9), running python 2.6.2.
Completion for this kind of things is tricky, because it would need to execute the actual code to work.
For example p.search() could return None or a MatchObject, depending on the data that is passed to it.
This is why omni-completion does not work here, and probably never will. It works for things that can be statically determined, for example a module's contents.
I never got the builtin omnicomplete to work for any languages. I had the most success with pysmell (which seems to have been updated slightly more recently on github than in the official repo). I still didn't find it to be reliable enough to use consistently but I can't remember exactly why.
I've resorted to building an extensive set of snipMate snippets for my primary libraries and using the default tab completion to supplement.

Categories