Skip to content

Commit

Permalink
Update type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Aug 22, 2023
1 parent e277fa9 commit 5e67525
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
16 changes: 8 additions & 8 deletions enum_tools/custom_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# stdlib
import sys
from enum import Enum, Flag, IntFlag
from typing import Any, Iterator
from typing import Any, Iterator, List

__all__ = [
"MemberDirEnum",
Expand All @@ -49,13 +49,13 @@
# stdlib
from enum import _high_bit

def _power_of_two(value):
def _power_of_two(value: int) -> bool:
# From CPython. Removed in https://github.com/python/cpython/commit/8cef9c0f92720f6810be1c74e00f611acb4b8b1e
if value < 1:
return False
return value == 2**_high_bit(value)

def _decompose(flag, value):
def _decompose(flag, value): # noqa: MAN001,MAN002
"""
Extract all members from the value.
"""
Expand Down Expand Up @@ -117,7 +117,7 @@ class MemberDirEnum(Enum):
.. versionadded:: 0.6.0
"""

def __dir__(self):
def __dir__(self) -> List[str]:
return super().__dir__() + [m for m in self.__dict__ if m[0] != '_']


Expand Down Expand Up @@ -192,22 +192,22 @@ class OrderedEnum(Enum):
:class:`~enum.Enum` that adds ordering based on the values of its members.
"""

def __ge__(self, other) -> bool:
def __ge__(self, other) -> bool: # noqa: MAN001
if self.__class__ is other.__class__:
return self._value_ >= other._value_
return NotImplemented

def __gt__(self, other) -> bool:
def __gt__(self, other) -> bool: # noqa: MAN001
if self.__class__ is other.__class__:
return self._value_ > other._value_
return NotImplemented

def __le__(self, other) -> bool:
def __le__(self, other) -> bool: # noqa: MAN001
if self.__class__ is other.__class__:
return self._value_ <= other._value_
return NotImplemented

def __lt__(self, other) -> bool:
def __lt__(self, other) -> bool: # noqa: MAN001
if self.__class__ is other.__class__:
return self._value_ < other._value_
return NotImplemented
Expand Down
2 changes: 1 addition & 1 deletion enum_tools/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class People(IntEnum):
"""

@classmethod
def iter_values(cls):
def iter_values(cls): # noqa: MAN002
"""
Iterate over the values of the Enum.
"""
Expand Down
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pathlib
import sys
import types
from typing import Iterator

# 3rd party
import pytest
Expand All @@ -16,21 +17,21 @@


@pytest.fixture(scope="session")
def rootdir():
def rootdir() -> path:
rdir = pathlib.Path(__file__).parent.absolute() / "doc-test"
if not (rdir / "test-root").is_dir():
(rdir / "test-root").mkdir(parents=True)
return path(rdir)


@pytest.fixture()
def content(app: Sphinx):
def content(app: Sphinx) -> Iterator[Sphinx]:
app.build()
yield app


@pytest.fixture()
def page(content, request) -> BeautifulSoup:
def page(content, request) -> BeautifulSoup: # noqa: MAN001
pagename = request.param
c = (content.outdir / pagename).read_text()

Expand Down
3 changes: 2 additions & 1 deletion tests/test_autoenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import pytest
import sphinx
from bs4 import BeautifulSoup, NavigableString # type: ignore
from sphinx_toolbox.testing import HTMLRegressionFixture
from sphinx.application import Sphinx
from sphinx_toolbox.testing import HTMLRegressionFixture

# this package
from enum_tools.autoenum import EnumDocumenter
Expand Down Expand Up @@ -46,6 +46,7 @@ class MyEnum(Enum):
def test_can_document_member():
assert EnumDocumenter.can_document_member(MyEnum, '', True, '')


def test(app: Sphinx) -> None:
# app is a Sphinx application object for default sphinx project (`tests/roots/test-root`).
app.build()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_documented_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class People(int, Enum):
"""

@classmethod
def iter_values(cls): # noqa: MAN001,MAN002
def iter_values(cls): # noqa: MAN002
return iter(cls)

#: A person called Dennis
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_documented_enum():
)
def test_document_enum_wrong_types(obj: object):
with pytest.raises(TypeError, match="'an_enum' must be an 'Enum', not .*!"):
document_enum(obj)
document_enum(obj) # type: ignore[type-var]


@pytest.mark.parametrize(
Expand All @@ -142,7 +142,7 @@ def test_document_enum_wrong_types(obj: object):
)
def test_document_member_wrong_types(obj: object):
with pytest.raises(TypeError, match="'an_enum' must be an 'Enum', not .*!"):
enum_tools.document_member(obj)
enum_tools.document_member(obj) # type: ignore[arg-type]


@xfail_313
Expand All @@ -162,7 +162,7 @@ class People(int, Enum):
Carol = 3 # doc: A person called Carol

@classmethod
def iter_values(cls): # noqa: MAN001,MAN002
def iter_values(cls): # noqa: MAN002
return iter(cls)

assert People.Bob == 1
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
)
def test_is_enum(obj: object, result: bool):
assert is_enum(obj) == result
assert is_enum(obj) == result # type: ignore[arg-type]


@pytest.mark.parametrize(
Expand All @@ -35,7 +35,7 @@ def test_is_enum(obj: object, result: bool):
]
)
def test_is_enum_member(obj: object, result: bool):
assert is_enum_member(obj) == result
assert is_enum_member(obj) == result # type: ignore[arg-type]


class Colours(enum.Flag):
Expand All @@ -60,7 +60,7 @@ class Colours(enum.Flag):
]
)
def test_is_flag(obj: object, result: bool):
assert is_flag(obj) == result
assert is_flag(obj) == result # type: ignore[arg-type]


def test_get_base_object():
Expand Down

0 comments on commit 5e67525

Please sign in to comment.