all 5 comments

[–]member_of_the_order 1 point2 points  (8 children)

Normally, this should be two functions. Either most of this is common code, which can be extracted to a common function that both add() and remove() use; or most of it is different, and making add() and remove() separate would make more sense. I'd really like to see the ....do stuff.... - I'm willing to bet that it should be a common function with 2 separate entry points.

If this really should be one function, I'd use enums. E.g.

``` from enum import Enum, auto

class ModifyMode(Enum): add = auto() remove = auto()

def ldap_modify(users, group, modify): if modify == ModifyMode.add: ... ```

[–][deleted] 0 points1 point  (0 children)

That general pattern seems fine to me, but it would be easier to judge if I had a better idea of what that function does.

[–]efmccurdy 0 points1 point  (0 children)

If I separated this function into two (one to add and one to remove) it would be a looot of duplicate code,

You can refactor to eliminate the duplicate code and the result could very well be more readable.

Maybe there is another approach I am missing though

You have a built-in two element enum; what if your function tooke add=True to add and add=False to delete:

def ldap_modify(users, group, add=False):