python - How to avoid circular dependencies in validation module -


i refactored code put input validation methods shared among several classes in own module, validate.py. of these validation methods check if input instance of class, e.g. myclass. therefore validate.py must import myclass it's method is_myclass can check if isinstance(input, myclass). but, want use validation methods validate.py in myclass sanitize input myclass.my_method, myclass must import validate.py.

something tells me casually refactored way anti-pattern. if i'm trying implies circular dependencies, must doing wrong™.

but, code reuse idea. what's best practice sharing validation methods in way?

i think parts of validation code specific 1 of classes should put class - maybe classmethod? way 'generic' validation code can call obj.validate() @ appropriate time. don't need import classes generic validation code.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -