Skip to content

Commit

Permalink
ci: fix after ruff/mypy updates
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Aug 28, 2024
1 parent aa3bd77 commit b4efc9a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
11 changes: 10 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# without it, pytest can't discover the package root for some reason
# also see https://github.com/karlicoss/pytest_namespace_pkgs for more

import os
import pathlib
from typing import Optional

Expand All @@ -24,6 +25,10 @@ def resolve_package_path(path: pathlib.Path) -> Optional[pathlib.Path]:
for parent in result.parents:
if str(parent) in namespace_pkg_dirs:
return parent
if os.name == 'nt':
# ??? for some reason on windows it is trying to call this against conftest? but not on linux/osx
if path.name == 'conftest.py':
return resolve_pkg_path_orig(path)
raise RuntimeError("Couldn't determine path for ", path)
_pytest.pathlib.resolve_package_path = resolve_package_path

Expand All @@ -34,5 +39,9 @@ def resolve_package_path(path: pathlib.Path) -> Optional[pathlib.Path]:
# not sure what are the consequences.. maybe it wouldn't be able to run against installed packages? not sure..
search_pypath_orig = _pytest.main.search_pypath
def search_pypath(module_name: str) -> str:
return str(root_dir)
mpath = root_dir / module_name.replace('.', os.sep)
if not mpath.is_dir():
mpath = mpath.with_suffix('.py')
assert mpath.exists(), mpath # just in case
return str(mpath)
_pytest.main.search_pypath = search_pypath
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ignore = [
lint.ignore = [
### too opinionated style checks
"E501", # too long lines
"E702", # Multiple statements on one line (semicolon)
Expand Down
2 changes: 1 addition & 1 deletion src/cachew/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_union_args(cls) -> Optional[Tuple[Type]]:
return None

args = cls.__args__
args = [e for e in args if e != type(None)]
args = [e for e in args if e is not type(None)]
assert len(args) > 0
return args

Expand Down
4 changes: 2 additions & 2 deletions src/cachew/tests/marshall.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def union_hook(data, type_):
# )
# NOTE: this seems to give a bit of speedup... maybe raise an issue or something?
# fmt: off
unstruct_func = converter._unstructure_func.dispatch(Type) # about 20% speedup
struct_func = converter._structure_func .dispatch(Type) # TODO speedup
unstruct_func = converter._unstructure_func.dispatch(Type) # type: ignore[call-arg, misc] # about 20% speedup
struct_func = converter._structure_func .dispatch(Type) # type: ignore[call-arg, misc] # TODO speedup
# fmt: on

to_json = unstruct_func
Expand Down
2 changes: 1 addition & 1 deletion src/cachew/tests/test_cachew.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def fun() -> Iterator[Exception]:
list(fun())
[e] = fun()
# not sure if there is anything that can be done to preserve type information?
assert type(e) == Exception
assert type(e) is Exception
assert e.args == ('whatever', 123, '2020-01-02T03:04:05', 'X(a=123)')


Expand Down
2 changes: 1 addition & 1 deletion src/cachew/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def is_namedtuple(t) -> bool:
b = getattr(t, '__bases__', None)
if b is None:
return False
if len(b) != 1 or b[0] != tuple:
if len(b) != 1 or b[0] is not tuple:
return False
f = getattr(t, '_fields', None)
if not isinstance(f, tuple):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ passenv =
[testenv:ruff]
commands =
{envpython} -m pip install --use-pep517 -e .[testing]
{envpython} -m ruff src/
{envpython} -m ruff check src/


# note: --use-pep517 here is necessary for tox --parallel flag to work properly
Expand Down

0 comments on commit b4efc9a

Please sign in to comment.