From e751d559ee82d5f0f49226a28d51a5f9b645d332 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 25 Mar 2021 14:01:59 +0200 Subject: [PATCH 1/2] Remove exclamation marks from exceptions --- src/prettytable/prettytable.py | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/prettytable/prettytable.py b/src/prettytable/prettytable.py index 2ade247d..d25ae4db 100644 --- a/src/prettytable/prettytable.py +++ b/src/prettytable/prettytable.py @@ -337,39 +337,39 @@ def _validate_field_names(self, val): try: assert len(val) == len(set(val)) except AssertionError: - raise Exception("Field names must be unique!") + raise Exception("Field names must be unique") def _validate_header_style(self, val): try: assert val in ("cap", "title", "upper", "lower", None) except AssertionError: raise Exception( - "Invalid header style, use cap, title, upper, lower or None!" + "Invalid header style, use cap, title, upper, lower or None" ) def _validate_align(self, val): try: assert val in ["l", "c", "r"] except AssertionError: - raise Exception(f"Alignment {val} is invalid, use l, c or r!") + raise Exception(f"Alignment {val} is invalid, use l, c or r") def _validate_valign(self, val): try: assert val in ["t", "m", "b", None] except AssertionError: - raise Exception(f"Alignment {val} is invalid, use t, m, b or None!") + raise Exception(f"Alignment {val} is invalid, use t, m, b or None") def _validate_nonnegative_int(self, name, val): try: assert int(val) >= 0 except AssertionError: - raise Exception(f"Invalid value for {name}: {val}!") + raise Exception(f"Invalid value for {name}: {val}") def _validate_true_or_false(self, name, val): try: assert val in (True, False) except AssertionError: - raise Exception(f"Invalid value for {name}! Must be True or False.") + raise Exception(f"Invalid value for {name}. Must be True or False.") def _validate_int_format(self, name, val): if val == "": @@ -379,7 +379,7 @@ def _validate_int_format(self, name, val): assert val.isdigit() except AssertionError: raise Exception( - f"Invalid value for {name}! Must be an integer format string." + f"Invalid value for {name}. Must be an integer format string." ) def _validate_float_format(self, name, val): @@ -397,52 +397,52 @@ def _validate_float_format(self, name, val): or (bits[1][-1] == "f" and bits[1].rstrip("f").isdigit()) ) except AssertionError: - raise Exception(f"Invalid value for {name}! Must be a float format string.") + raise Exception(f"Invalid value for {name}. Must be a float format string.") def _validate_function(self, name, val): try: assert hasattr(val, "__call__") except AssertionError: - raise Exception(f"Invalid value for {name}! Must be a function.") + raise Exception(f"Invalid value for {name}. Must be a function.") def _validate_hrules(self, name, val): try: assert val in (ALL, FRAME, HEADER, NONE) except AssertionError: raise Exception( - f"Invalid value for {name}! Must be ALL, FRAME, HEADER or NONE." + f"Invalid value for {name}. Must be ALL, FRAME, HEADER or NONE." ) def _validate_vrules(self, name, val): try: assert val in (ALL, FRAME, NONE) except AssertionError: - raise Exception(f"Invalid value for {name}! Must be ALL, FRAME, or NONE.") + raise Exception(f"Invalid value for {name}. Must be ALL, FRAME, or NONE.") def _validate_field_name(self, name, val): try: assert (val in self._field_names) or (val is None) except AssertionError: - raise Exception(f"Invalid field name: {val}!") + raise Exception(f"Invalid field name: {val}") def _validate_all_field_names(self, name, val): try: for x in val: self._validate_field_name(name, x) except AssertionError: - raise Exception("fields must be a sequence of field names!") + raise Exception("Fields must be a sequence of field names") def _validate_single_char(self, name, val): try: assert _str_block_width(val) == 1 except AssertionError: - raise Exception(f"Invalid value for {name}! Must be a string of length 1.") + raise Exception(f"Invalid value for {name}. Must be a string of length 1.") def _validate_attributes(self, name, val): try: assert isinstance(val, dict) except AssertionError: - raise Exception("attributes must be a dictionary of name/value pairs!") + raise Exception("Attributes must be a dictionary of name/value pairs") ############################## # ATTRIBUTE MANAGEMENT # @@ -949,7 +949,7 @@ def set_style(self, style): elif style == RANDOM: self._set_random_style() else: - raise Exception("Invalid pre-set style!") + raise Exception("Invalid pre-set style") def _set_orgmode_style(self): self._set_default_style() @@ -1053,7 +1053,7 @@ def del_row(self, row_index): if row_index > len(self._rows) - 1: raise Exception( f"Can't delete row at index {row_index}, " - f"table only has {len(self._rows)} rows!" + f"table only has {len(self._rows)} rows" ) del self._rows[row_index] @@ -1084,7 +1084,7 @@ def add_column(self, fieldname, column, align="c", valign="t"): else: raise Exception( f"Column length {len(column)} does not match number of rows " - f"{len(self._rows)}!" + f"{len(self._rows)}" ) def del_column(self, fieldname): @@ -1935,6 +1935,6 @@ def from_html_one(html_code, **kwargs): assert len(tables) == 1 except AssertionError: raise Exception( - "More than one in provided HTML code! Use from_html instead." + "More than one
in provided HTML code. Use from_html instead." ) return tables[0] From f3a9d7cfc8f9c0136861e9787e243a7a65148023 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 25 Mar 2021 14:48:57 +0200 Subject: [PATCH 2/2] pre-commit autoupdate --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a59ca91c..53ea29b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.7.4 + rev: v2.11.0 hooks: - id: pyupgrade args: ["--py36-plus"] @@ -12,18 +12,18 @@ repos: args: ["--target-version", "py36"] - repo: https://github.com/PyCQA/isort - rev: 5.7.0 + rev: 5.8.0 hooks: - id: isort - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.0 hooks: - id: flake8 additional_dependencies: [flake8-2020, flake8-implicit-str-concat] - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.7.0 + rev: v1.8.0 hooks: - id: python-check-blanket-noqa