Skip to content

Commit

Permalink
Revert "Fix mypy for PgVersion"
Browse files Browse the repository at this point in the history
This reverts commit 259275f.
  • Loading branch information
bayandin committed Oct 25, 2024
1 parent 259275f commit b9d85db
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions test_runner/fixtures/pg_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class PgVersion(StrEnum):
# to explicitly rely on the default server version (could be different from pg_version fixture value)
NOT_SET = "<-POSTRGRES VERSION IS NOT SET->"

# Allow PgVersion to accept str or int
# https://docs.python.org/3.11/library/enum.html#supported-dunder-names
@classmethod
@override
def __new__(cls, value: int | str):
return super().__new__(cls, str(value))

# Make it less confusing in logs
@override
def __repr__(self) -> str:
Expand All @@ -48,20 +41,18 @@ def v_prefixed(self) -> str:
@classmethod
@override
def _missing_(cls, value: object) -> PgVersion | None:
if not isinstance(value, str):
return None

known_values = {v.value for _, v in cls.__members__.items()}

# Allow passing version as v-prefixed string (e.g. "v14")
if value.lower().startswith("v") and (v := value[1:]) in known_values:
return cls(v)
# Allow passing version as an int (in __new__ it's converted to str)
# (e.g. 15 or 150002, both will be converted to PgVersion.V15)
elif value.isdigit() and (v := value[:2]) in known_values:
return cls(v)
else:
return None
# Allow passing version as a string with "v" prefix (e.g. "v14")
if isinstance(value, str) and value.lower().startswith("v") and value[1:] in known_values:
return cls(value[1:])
# Allow passing version as an int (e.g. 15 or 150002, both will be converted to PgVersion.V15)
elif isinstance(value, int) and str(value)[:2] in known_values:
return cls(str(value)[:2])

# Make mypy happy
# See https://github.com/python/mypy/issues/3974
return None


DEFAULT_VERSION: PgVersion = PgVersion.V16
Expand Down

0 comments on commit b9d85db

Please sign in to comment.