the syntax rules for python incorrectly consider, say, both `filter` and `obj.filter` as instances of the builtin `filter`. I've added a rule to explicitly set the group of attributes (defined as an identifier following a dot) to none. Maybe it's better to create a new group for attributes, I'm not sure. I will update the patch with any improving suggestion.
Cheers
--
Carlos
> - Is there any value in making an exception for only a.filter line?
Yes, you can say for (99%) sure that a.filter is not a builtin, at least no more than a.x. Instead it's dubious practice to name a global or local variable as a builtin, that's looking for trouble. But attributes and variables are different beasts, differently scoped.
There's little to say against value.set(3) or point.set(x=3, y=2) but a lot against def set(obj, attr, val): .... or set = [1, 2, 3].
Cheers
--
Carlos
> OK. But there still remains the question of discrepancy between:
>
> class A:
> filter = None
Here filter is a variable locally scoped to the block defined by A, in that sense this is not different from:
def a():
filter = None
Both clashes with the "auto-global" builtin.
Fortunately the most common case will be:
class A:
def filter(...): ...
where filter would be highlighted because of the def anyway.
> and:
>
> a = A()
> a.filter = 2
Here a (and even A) is a potential offender but not filter, which is resolved inside a.
The rule is simple: an unqualified variable named like a builtin is highlighted to signal potential mistakes / bad smell.
There already is a variable to control highlighting of builtins. Currently it's a toggle but it could have 3 levels instead:
0: never.
1: only unqualified.
2: always.
Heuristically I think 1 does a better job, but you can set the default to 2 if you prefer.
Cheers
--
Carlos
> >
> > class A:
> > filter = None
>
You could also avoid highlighting left hand sides as they're easy to match. A variable that is always assigned to would be weird but never confused with a builtin, as it's clear it's being bound at that point. Now, any potential *use* of a builtin (i.e. not a lhs) will be highlighted as usual.
I don't care a lot about this case though.
Cheers
--
Carlos
On Aug 1, 2015, at 3:41 AM, Carlos Pita <carlosj...@gmail.com> wrote:> OK. But there still remains the question of discrepancy between:
>
> class A:
> filter = NoneHere filter is a variable locally scoped to the block defined by A, in that sense this is not different from:
def a():
filter = None
Both clashes with the "auto-global" builtin.
Fortunately the most common case will be:
class A:
def filter(...): ...
where filter would be highlighted because of the def anyway.
> and:
>
> a = A()
> a.filter = 2Here a (and even A) is a potential offender but not filter, which is resolved inside a.
The rule is simple: an unqualified variable named like a builtin is highlighted to signal potential mistakes / bad smell.
There already is a variable to control highlighting of builtins. Currently it's a toggle but it could have 3 levels instead:
0: never.
1: only unqualified.
2: always.Heuristically I think 1 does a better job, but you can set the default to 2 if you prefer.