Conversation
d268b71 to
b85e299
Compare
b85e299 to
28e5819
Compare
| raise InvalidDateRange | ||
| except ValueError: | ||
| raise InvalidDate | ||
| except AttributeError: | ||
| except (ValueError, AttributeError): | ||
| raise InvalidDate |
There was a problem hiding this comment.
Function Reservation.__init__ refactored with the following changes:
- Merge except handlers with identical code blocks (
merge-except-handler)
| except ValueError: | ||
| raise InvalidDate | ||
| except AttributeError: | ||
| except (ValueError, AttributeError): |
There was a problem hiding this comment.
Function Rent.__init__ refactored with the following changes:
- Merge except handlers with identical code blocks (
merge-except-handler)
| } | ||
|
|
||
| if type == "Van": | ||
| elif type == "Van": |
There was a problem hiding this comment.
Function cars_as_dict refactored with the following changes:
- Simplify conditional into switch-like form (
switch)
| overdue = [] | ||
| if cars: | ||
| overdue = [] |
There was a problem hiding this comment.
Function overdue_cars refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| cars_as_list = cars_as_dict(cars) | ||
| if len(criteria) != 0: | ||
| for car in cars_as_list: | ||
| criteria_met = 0 | ||
| criteria_size = len(criteria) | ||
| for crit_name in criteria: | ||
| crit = criteria[crit_name] | ||
| car_crit = car[crit_name] | ||
| if isinstance(crit, dict): | ||
| if crit_name == 'Rent': | ||
| if car_crit is not None and crit['Return date'] is not None: | ||
| car_date = datetime.strptime(car_crit['Return date'], '%d.%m.%Y').date() | ||
| crit_date = datetime.strptime(crit['Return date'], '%d.%m.%Y').date() | ||
| if car_crit is None or crit['Return date'] is None or car_date < crit_date: | ||
| criteria_met += 1 | ||
| continue | ||
| if crit_name == 'Reservation': | ||
| if car_crit is not None and crit['Due Reservation Date'] is not None: | ||
| car_date = datetime.strptime(car_crit['Due Reservation Date'], '%d.%m.%Y').date() | ||
| crit_date = datetime.strptime(crit['Due Reservation Date'], '%d.%m.%Y').date() | ||
| if car_crit is None or crit['Due Reservation Date'] is None or car_date < crit_date: | ||
| criteria_met += 1 | ||
| continue | ||
| if len(criteria) == 0: | ||
| return [] | ||
|
|
||
| criteria_size += len(crit) | ||
| for add in crit: | ||
| if crit[add] != '': | ||
| try: | ||
| if crit[add] == car_crit[add] or crit[add] == '': | ||
| criteria_met += 1 | ||
| except Exception: | ||
| pass | ||
| else: | ||
| criteria_met += 1 | ||
| criteria_met += 1 | ||
| else: | ||
| if crit == car_crit or crit == '': | ||
| criteria_meeting = [] | ||
| for car_index, car in enumerate(cars_as_list): | ||
| criteria_met = 0 | ||
| criteria_size = len(criteria) | ||
| for crit_name in criteria: | ||
| crit = criteria[crit_name] | ||
| car_crit = car[crit_name] | ||
| if isinstance(crit, dict): | ||
| if crit_name == 'Rent': | ||
| if car_crit is not None and crit['Return date'] is not None: | ||
| car_date = datetime.strptime(car_crit['Return date'], '%d.%m.%Y').date() | ||
| crit_date = datetime.strptime(crit['Return date'], '%d.%m.%Y').date() | ||
| if car_crit is None or crit['Return date'] is None or car_date < crit_date: | ||
| criteria_met += 1 | ||
| if(criteria_met == criteria_size): | ||
| car_class = cars[car_index] | ||
| criteria_meeting.append(car_class) | ||
| car_index += 1 | ||
| return criteria_meeting | ||
| else: | ||
| return [] | ||
| continue | ||
| if crit_name == 'Reservation': | ||
| if car_crit is not None and crit['Due Reservation Date'] is not None: | ||
| car_date = datetime.strptime(car_crit['Due Reservation Date'], '%d.%m.%Y').date() | ||
| crit_date = datetime.strptime(crit['Due Reservation Date'], '%d.%m.%Y').date() | ||
| if car_crit is None or crit['Due Reservation Date'] is None or car_date < crit_date: | ||
| criteria_met += 1 | ||
| continue | ||
|
|
||
| criteria_size += len(crit) | ||
| for add in crit: | ||
| if crit[add] != '': | ||
| try: | ||
| if crit[add] == car_crit[add]: | ||
| criteria_met += 1 | ||
| except Exception: | ||
| pass | ||
| else: | ||
| criteria_met += 1 | ||
| criteria_met += 1 | ||
| elif crit in [car_crit, '']: | ||
| criteria_met += 1 | ||
| if(criteria_met == criteria_size): | ||
| car_class = cars[car_index] | ||
| criteria_meeting.append(car_class) | ||
| return criteria_meeting |
There was a problem hiding this comment.
Function search_database refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Move assignments closer to their usage (
move-assign) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| self.cars = read_from_database() | ||
| else: | ||
| self.cars = [] | ||
| self.cars = read_from_database() or [] |
There was a problem hiding this comment.
Function CarRentalWindow.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify if expression by using or (
or-if-exp-identity)
| if car.reservation: | ||
| if car.reservation.check_expiration() == "EXPIRED": | ||
| car.reservation = None | ||
| if car.reservation and car.reservation.check_expiration() == "EXPIRED": | ||
| car.reservation = None |
There was a problem hiding this comment.
Function CarRentalWindow.check_reservations refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.65%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!