Skip to content

Commit

Permalink
Merge pull request #7 from wppbav:dev-intenum-no-override
Browse files Browse the repository at this point in the history
Don't override `IntEnum.__str__` method
  • Loading branch information
nachomaiz authored Jul 19, 2023
2 parents edcf387 + 6026a8c commit 1d32cb8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
12 changes: 8 additions & 4 deletions bavapi/reference/_int_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
# pylint: disable=useless-import-alias

import sys
from enum import IntEnum as IntEnum
from enum import IntEnum as _IntEnum

__all__ = ("IntEnum",)

if sys.version_info < (3, 11):

def _int_enum_str(self: IntEnum) -> str:
return str(self.value)
class IntEnum(_IntEnum):
"""Patched IntEnum pre Python 3.11."""

IntEnum.__str__ = _int_enum_str
def __str__(self) -> str:
return str(self.value)

else:
IntEnum = _IntEnum
7 changes: 5 additions & 2 deletions bavapi/sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Convenience functions to perform queries to the Fount synchronously.
"""
Convenience functions to perform queries to the Fount synchronously.
Can be used directly without using `asyncio`.
Can be used directly without `asyncio`.
Meant for experimentation, Jupyter notebooks, one-off scripts, etc.
Expand Down Expand Up @@ -332,6 +333,8 @@ async def brandscape_data(
If `fields` is None, all fields are returned.
include : str or list[str], optional
Additional resources to include in API response, by default None
metric_keys: str or list[str], optional
Key or list of keys for the metrics included in the response, by default None
stack_data : bool, optional
Whether to expand nested lists into new dictionaries, by default False
**kwargs
Expand Down
6 changes: 0 additions & 6 deletions tests/reference/test_int_enum.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# pylint: disable=missing-class-docstring, missing-module-docstring, missing-function-docstring

import sys

import pytest

from bavapi.reference._int_enum import IntEnum


@pytest.mark.skipif(sys.version_info >= (3, 11), reason="not needed after python 3.11")
def test_int_enum_str():
class MockRef(IntEnum):
A = 1

assert str(MockRef.A) == "1"
assert MockRef.A.__str__.__name__ == "_int_enum_str"
2 changes: 1 addition & 1 deletion type_stubs/nest_asyncio.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pylint: disable=missing-module-docstring, missing-function-docstring, unused-argument
# pylint: disable=missing-module-docstring, missing-function-docstring, unused-argument

import asyncio

Expand Down

0 comments on commit 1d32cb8

Please sign in to comment.