VSCode Intellisense stopped working properly for python - python

I noticed any variables I make in python will no longer have proper IntelliSense suggestions. It seems that my VSCode is treating every variable I make as the same type?
Here is how it is right now
Here is how it looks when I'm typing in the variable
Here is how it looks on my Mac
According to the Intellisense page on VSCodes websites the blue box symbol that appears when I'm calling the variable means its a field while the other symbol on my mac means its a Values and Enumerations. How can I make my desktop the same as my mac.
Also when I am typing an existing variable out and I add a "." to use a function on the variable and hit enter it will just copy the variable name again.I only get suggestions for intellisense if I have 2 ".". So stringG..

I guess you changed some setting accidently, the fastest solution here is uninstall/install again!

Related

Autocompletion in PyCharm based on type

I'm using PyCharm for python coding. The autocompletion in PyCharm is not as good as in IntelliJ (Java). Consider the below code
a = [1,2,3,4]
a.
In this case, after I press the dot, PyCharm gives the full set of autocompletion options. Consider the below case
def func_a(a):
a.
Here, to the function func_a I'm passing a list as an argument. But when I press dot after a, PyCharm doesn't give any autocompletion options. I know this is because Python is dynamically typed language and PyCharm has no idea to determine what type a is.
But is there any way to tell PyCharm the type of a, may be in documentation comment or something like that? So, that PyCharm can give valid autocompletion options?
Yes, Python 3.5 introduces type hinting and Pycharm utilizes that.
Use
def func_name(param: type) -> return_type:
Like
def func_a(a: list):
Note that all type hints are completely optional and ignored by the interpreter. However, Pycharm can potentially help you detect type errors if you use it as a habit.
This might not answer your question but this will be helpful for those who just started using pycharm for Django application.
PyCharm does not give (It underlines some built in functions with red) auto-completion option for Django if you have started project with Pure Python. Pure Python option comes when you click on new project option from file menu or when you run pycharm to start new project. Pure Python is the default selected option on new project page. You should choose Django (the 2nd option) to get auto-completion option in PyCharm.
Hope this would be helpful for others.
Can do : (examples using list):
def func_a(a:list):
do_this()
Or manually check:
def func_a(a):
if isinstance(a,list):
do_this
else:
raise TypeError("expected type of 'list' but got type of '%s'"%type(a).__name__)

Python Syntax Highlighting in Xcode

Is there any way to achieve better syntax highlighting in Xcode for Python? Xcode only identifies and colorizes keywords, strings, numbers and comments. It doesn't seem to be able to identify the self variable name that represents instance objects. I've experimented with other color themes but it doesn't change the fact that Xcode cannot identify names for instance objects in Python. Is there any way to achieve better syntax highlighting?
I'm using xcode12;after you have setup python properly in xcode.(refer to this if you are not sure of your setup: https://youtu.be/h8_68OONY-w)
Now to get back 'syntax highlighting' for python code.Click on the 'Editor' tab on the menu bar, click on 'syntax colouring' and choose 'python' from the list and you must be fine.

Can I update pycharm intellisense for python?

I want to know if it's possible to update Pycharm intellisense for python which doesn't care about capital or normal letters?
It's a pain in the neck to try both each time.
Currently I'm using pycharm 3.0 and python 2.7.4
An example of what I want:
For example I have a model named: 'MyModel'
I use to type first two letters and then ctrl+space to choose from the list. so if I type 'my' instead of 'My', the pycharm says: 'No suggestion'
You want to set the Case sensitive completion to None.
In PyCharm 2016.3 this is in Settings > Editor > General > Code Completion.

Viewing object attributes with tab completion in sublimerepl python

In the IDLE interpreter in Python, you can see a drop-down list of an object's attributes by typing the object's name, then period, then hitting TAB.
Is it possible to get similar functionality with sublimerepl?
I've tried the different autocomplete packages, but they don't appear to make this happen.
So there are many different packages, Andy's package being my favorite. None provide every method for a given function but try hitting "ctrl-space" after the period to see what's available!
Link:
https://sublime.wbond.net/packages/AndyPython

Python Strongly type lists

I am using eclipse for python and I am facing a problem. I have many classes with many properties and want a list of objects from one of my declared classes. The problem is: When I am accessing any item from the list, the IDE does not know its type because in python we do not declare the variable with type, so there is no auto complete and I have to go to the class to copy the attribute name.
To make idea more clear:
class AutomataBranch(object):
def __init__(selfparams):
self.Name="";
self.nodes=[];
class LanguageAutomata(object):
def __init__(selfparams):
self.cfgAutomata=[];#This has AutomaBranch Type
Now in any method in LanguageAutomata class if I wrote:
cfgAutomata. Then it wont give me the Name attribute
Is there any solution for that?
Python is strongly typed and Python lists are too. Your problem come from the fact that Python is dynamically typed. Therefor a var can contain any type, and therefor no IDE can guess what is the type of your parameter, nor give you code completion for the methods.
This is how it is, there is no clean workaround. If it's a problem, then maybe dynamics language is not you predilection tool and you should use something that fit your development style. There are tools for everybody.
8 years later and we actually have a solution in Python 3.6.
PEP484 allows you to annotate your variables primarily for IDEs and linting:
Modifying #Hani's answer:
x : AutomataBranch = self.cfgAutomata[i]
This is now picked up by any good IDE to highlight errors and allow autocomplete.
I think you mean to say "statically typed" instead of "strongly typed." Python is strongly typed. You just don't know what that type is at compile time.
With that said, you really need to abandon the idea that you're going to find any IDEs that work as well for Python as they do for Java or C#. Python's dynamic typing makes this difficult. In fact, I tend to find that powerful IDEs are more of a burden than a help.
I think I found a good managable solution. Actually it is trivial but may help (I used it now).
When I want to access the list then I assign the object which I want to access to a variable ex:
x = AutomataBranch()
x = self.cfgAutomata[i]
The first line is used only to make the IDE knows that x is from AutomatBranch type. After that when I press x then all methods and properties are visualized.
I think it is some how good.

Categories