Unfortunately (from the point of view of highlighting) with a totally dynamic 
language like Python you must effectively execute the code to find the type of 
a name.  And without knowing that any expression based on the name cannot be 
known.

In your example, `example`, `__init__`, and `world` are declarations, that is 
syntax that explicitly defines a name and what type it is (`example` is a 
class, and `__init__` and `world` are functions and the highlighter identifies 
them as such).

But in `e=example()` there is no syntax to say `e` is being declared, it is an 
assignment expression which would have to be evaluated, or at least type 
inferred, to decide that `e` is being declared here, and evaluation and type 
inference is beyond the pay grade of simple syntax highlighters.

Even `example()` is no guarantee that it is a class instantiation, since Python 
is a dynamic language the name can be redefined between the class declaration 
and the use of `example()` so as I said evaluation or complex type inference 
would be needed to see what `example` is bound to at any point in the code.  
And also the type of a name may be different depending on which branch of an 
`if` the code takes, eg:

```
if foo:
   blah=example()
else:
   blah=other()
blah.x
```
So what is `blah` and `blah.x`, depends on `foo` and that might be the result 
of a data read, but at least it involves evaluating the code that sets `foo`.

AFAICT even IDEs like Eclipse or Python's own Idle don't do any better with 
highlighting.

Static languages do better with highlighting because all names are declared, 
and the type of names can't be changed, although it still isn't perfect due to 
scope issues.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/issues/2441#issuecomment-587928366

Reply via email to