Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, fix mypy #377

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def mypy(session: Session) -> None:
"pytest",
"types-setuptools",
"pandas-stubs",
"pyarrow-stubs",
"types-Pygments",
"types-colorama",
"types-beautifulsoup4",
Expand Down
1,517 changes: 848 additions & 669 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typeguard = ">=2.13.3"
xdoctest = { extras = ["colors"], version = ">=0.15.10" }
myst-parser = { version = ">=0.16.1" }
pandas-stubs = "*"
pyarrow-stubs = ">=10.0.1.9"
types-Pygments = "*"
types-colorama = "*"
types-setuptools = "*"
Expand Down
3 changes: 1 addition & 2 deletions src/datadoc/backend/dataset_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ def __init__(self, dataset: pathlib.Path | CloudPath) -> None:
def get_fields(self) -> list[Variable]:
"""Extract the fields from this dataset."""
with self.dataset.open(mode="rb") as f:
# Type stubs for pyarrow are incorrect see https://github.com/zen-xu/pyarrow-stubs/issues/4
schema: pa.Schema = pq.read_schema(f) # type: ignore # noqa: PGH003
schema: pa.Schema = pq.read_schema(f) # type: ignore [arg-type]
return [
Variable(
short_name=data_field.name.strip(),
Expand Down
17 changes: 0 additions & 17 deletions src/datadoc/frontend/callbacks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
import logging
from typing import TYPE_CHECKING
from typing import TypeAlias
from typing import cast

import arrow
from datadoc_model import model

from datadoc import config
from datadoc import enums
from datadoc import state
from datadoc.frontend.components.dataset_tab import build_dataset_tab
from datadoc.frontend.components.variables_tab import build_variables_tab

if TYPE_CHECKING:
import pathlib
from enum import Enum

import pydantic
from cloudpathlib import CloudPath
Expand All @@ -34,20 +31,6 @@
)


def get_language_strings_enum(
enum: Enum | type[enums.LanguageStringsEnum],
) -> enums.LanguageStringsEnum:
"""Get the correct language strings enum for the given enum.

We need multiple languages to display in the front end, but the model only defines a single language in the enums.
"""
language_strings_enum: enums.LanguageStringsEnum = getattr(
enums,
cast(type[enums.LanguageStringsEnum], enum).__name__,
)
return language_strings_enum


def _check_if_language_string_item_exists(
language_strings: model.LanguageStringType,
language_code: str,
Expand Down
9 changes: 4 additions & 5 deletions src/datadoc/frontend/fields/display_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
from dash import html

from datadoc import state
from datadoc.enums import LanguageStringsEnum
from datadoc.enums import SupportedLanguages
from datadoc.frontend.callbacks.utils import get_language_strings_enum

if TYPE_CHECKING:
from collections.abc import Callable
from enum import Enum

from dash.development.base_component import Component
from datadoc_model.model import LanguageStringType
Expand Down Expand Up @@ -58,15 +57,15 @@


def get_enum_options(
enum: Enum,
enum: type[LanguageStringsEnum],
) -> list[dict[str, str]]:
"""Generate the list of options based on the currently chosen language."""
dropdown_options = [
{
"title": i.get_value_for_language(SupportedLanguages.NORSK_BOKMÅL),
"title": i.get_value_for_language(SupportedLanguages.NORSK_BOKMÅL) or "",
"id": i.name,
}
for i in get_language_strings_enum(enum) # type: ignore [attr-defined]
for i in enum # type: ignore [attr-defined]
]
dropdown_options.insert(0, {"title": DROPDOWN_DESELECT_OPTION, "id": ""})
return dropdown_options
Expand Down
29 changes: 0 additions & 29 deletions tests/frontend/callbacks/test_callbacks_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from enum import Enum

import pytest
from dash import html
from datadoc_model import model

from datadoc.enums import LanguageStringsEnum
from datadoc.frontend.callbacks.utils import find_existing_language_string
from datadoc.frontend.callbacks.utils import get_language_strings_enum
from datadoc.frontend.callbacks.utils import render_tabs


Expand Down Expand Up @@ -58,31 +54,6 @@ def test_find_existing_language_string_pre_existing_strings(
)


@pytest.mark.parametrize(
"model_enum",
[
model.Assessment,
model.DataSetStatus,
model.DataSetState,
model.DataType,
model.VariableRole,
model.TemporalityTypeType,
],
)
def test_get_language_strings_enum(model_enum: Enum):
assert issubclass(get_language_strings_enum(model_enum), LanguageStringsEnum) # type: ignore [arg-type]


def test_get_language_strings_enum_unknown():
class TestEnum(Enum):
"""Test enum."""

TEST = "test"

with pytest.raises(AttributeError):
get_language_strings_enum(TestEnum)


@pytest.mark.parametrize(
("tab", "content"),
[
Expand Down