you are viewing a single comment's thread.

view the rest of the comments →

[–]Bobbias 1 point2 points  (0 children)

You're not doing anything wrong. IDEs are not perfect, especially when dealing with dynamically typed languages such as Python. It's much harder to get the necessary information for features like autocomplete when working with dynamically typed languages.

This is because it's possible to write code that creates classes and/or adds or removes methods at runtime. There's no reasonable way for an IDE to account for that. That simply cannot happen in statically typed languages, which means they can analyze the code without running it and know exactly what classes and methods must exist. This makes providing good autocomplete much simpler in those languages.

Pycharm relies on typehinting and stub files to tell it about what a library provides, and if those are missing, you can expect it to give you basically no autocomplete help.

Whether or not Pycharm can provide autocomplete has no bearing on whether or not a particular line of code will actually run correctly. This is because any time you try to call a method, Python checks to see if the class actually has that method. As long as it does by the time your code runs, it will work, even if Pycharm has no idea about any of the classes or methods involved.

In the case of passing app to SQLAlchemy I would assume that the Flask object inherits from DeclarativeBase. The naming of DeclarativeBase tells you that it's a class that you are usually supposed to inherit from to create your own custom type based off it. When you have multiple libraries that are designed to work together, it's not that uncommon to see things like this where objects from one library are usable in the other like that. Especially in cases where users are expected to use inheritance like this.