Let's say I have a Python class as below:
class Foo:
one = 'some value'
two = 'some other value'
# ... and so on ...
twenty = 'blah blah'
one = 'updated value' # OH NOEEESSS :o
I want to detect (and possibly prevent) the re-declaration of Foo.one
in the class body.
Is there any way to detect this programmatically at runtime, or even via a lint rule?
If it helps, my use case is a bit more specific. I want to avoid re-using column names of Flask SQLAlchemy models, where I have a long list of columns and I risk re-using old column names while trying to add new columns. For example:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class UserModel(db.Model):
""" A sample user model """
__tablename__ = 'user'
name = db.Column(db.String)
is_dead = db.Column(db.Boolean)
# ... and so on ...
name = db.Column(db.String) # Detect/prevent re-declaration of 'name'