Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify logical expression in Multiple Functions #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Simplify logical expression in Multiple Functions #175

wants to merge 1 commit into from

Conversation

yezz123
Copy link

@yezz123 yezz123 commented Sep 9, 2021

  • Simplify logical expression using De Morgan identities and Remove redundant conditional in this Function AuthBackend.authenticate.
  • Add a guard clause and Convert for loop into dictionary comprehension in this Function Serializer.update_one.
  • Refactoring this Function parse_error with these changes :

Merge duplicate blocks in conditional
Replace unneeded comprehension with generator
Merge else clause's nested if statement into elif.

  • Swap if/else branches and Remove unnecessary else after guard condition in this Function ValidationErrorLoggingRoute.get_route_handler.custom_route_handler.

@yezz123
Copy link
Author

yezz123 commented Sep 9, 2021

serializer = TestSerializer(c="2", int_sequence=(x for x in [2, 3]))

Relate to this we can simplify the generator

The expression (x for x in [2, 3]) is a generator that returns all of the elements of [2, 3]. If being passed into a function like any or all that takes a generator or sequence, it can simply be replaced by [2, 3] which is much clearer.

After simplifying the generator we can use iter:

    serializer = TestSerializer(c="2", int_sequence=iter([2, 3]))
    assert list(serializer.int_sequence) == [2, 3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant