Hello people.
I’m working on a CPython 3.10 project that uses flask_wtf.FlaskForm. I’m currently going through it with Vulture and removing dead code.
Our forms have a bunch of things like:
class CreateTransactionForm(FlaskForm):
pipeline = IntegerField("pipeline", validators=[Required()])
variant = IntegerField("variant", validators=[Required()])
token = IntegerField("token", validators=[Optional()])
type = IntegerField("type")
@staticmethod
def validate_type(form, field):
if not VersionType.Exists(field.data):
raise ValidationError("Unknown version type value")
That ‘validate_type’ method looks like it should be getting used to automatically validate the ‘type’ field - but I don’t think it is, because:
- Vulture identifies it as dead code.
- I added a ‘raise NotImplementedError’ to the beginning of each ‘def validate_*’, ran the software, and I got no new exceptions.
But we have a bunch of such methods, and the code looks like it might be nice to have - so rather than delete these methods, maybe there’s a good way of enabling their use?
My question is, can I somehow make such validate_foo methods get used for validating a WTForms ‘foo’ class variable? I’m assuming it involves inheritance and some form of metaclass or class introspection. I get inheritance, but I don’t know much about metaclasses and class introspection.
Any suggestions?
TIA!