Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jun 30, 2023
1 parent da4c173 commit a5940d1
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
exclude: ^tests|^docs

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
rev: v0.0.275
hooks:
- id: ruff
args: [--fix]
Expand All @@ -25,7 +25,7 @@ repos:
exclude: ^docs

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.4.1
hooks:
- id: mypy
exclude: ^tests|^docs|_napari_plugin|widgets
15 changes: 11 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ dev = [
"xsdata-pydantic-basemodel @ git+https://github.com/tlambert03/xsdata-pydantic-basemodel",
"mypy",
]
docs = ["numpydoc", "pygments", "sphinx==5.3.0", "sphinx-rtd-theme==1.1.1", "ipython"]
docs = [
"numpydoc",
"pygments",
"sphinx==5.3.0",
"sphinx-rtd-theme==1.1.1",
"ipython",
]
test = ["pytest", "pytest-cov", "pytest-benchmark", "xmlschema"]


Expand Down Expand Up @@ -93,13 +99,14 @@ select = [
"E", # style errors
"F", # flakes
"D", # pydocstyle
"I001", # isort
"I", # isort
"UP", # pyupgrade
# "N", # pep8-naming
"S", # bandit
"C", # flake8-comprehensions
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"A001", # flake8-builtins
"TID", # tidy
"TCH", # typechecking
"RUF", # ruff-specific rules
]
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion src/ome_autogen/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .main import build_model
from ome_autogen.main import build_model

build_model()
3 changes: 2 additions & 1 deletion src/ome_autogen/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import subprocess
import sys
from pathlib import Path

from xsdata.codegen.transformer import SchemaTransformer

from ome_autogen import _util
from ome_autogen._config import OUTPUT_PACKAGE, get_config

DO_MYPY = os.environ.get("OME_AUTOGEN_MYPY", "0") == "1"
DO_MYPY = os.environ.get("OME_AUTOGEN_MYPY", "0") == "1" or "--mypy" in sys.argv
SRC_PATH = Path(__file__).parent.parent
SCHEMA_FILE = SRC_PATH / "ome_types" / "ome-2016-06.xsd"
RUFF_IGNORE: list[str] = [
Expand Down
4 changes: 2 additions & 2 deletions src/ome_types/_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import io
from dataclasses import is_dataclass
from pathlib import Path
from struct import Struct
Expand All @@ -12,6 +11,7 @@
from xsdata_pydantic_basemodel.bindings import XmlParser, XmlSerializer

if TYPE_CHECKING:
import io
from typing import TypedDict

from xsdata.formats.dataclass.parsers.mixins import XmlHandler
Expand Down Expand Up @@ -53,7 +53,7 @@ def to_dict(source: OME | Path | str | bytes) -> dict[str, Any]:
)


def _class_factory(cls: type, kwargs: Any):
def _class_factory(cls: type, kwargs: Any) -> Any:
kwargs.setdefault("validation", "strict")
return cls(**kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/ome_types/_mixins/_base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __repr__(self) -> str:

@validator("id", pre=True, always=True, check_fields=False)
@classmethod
def _validate_id(cls, value: Any, values=None, config=None) -> Any:
def _validate_id(cls, value: Any) -> Any:
"""Pydantic validator for ID fields in OME models.
If no value is provided, this validator provides and integer ID, and stores the
Expand Down
3 changes: 2 additions & 1 deletion src/ome_types/_mixins/_ome.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

import weakref
from pathlib import Path
from typing import TYPE_CHECKING, Any, cast

from ._base_type import OMEType

if TYPE_CHECKING:
from pathlib import Path

from ome_types.model import OME, Reference


Expand Down
11 changes: 6 additions & 5 deletions src/ome_types/_mixins/_structured_annotations.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import Iterable, Sequence, TypeVar, overload
from typing import Iterator, Sequence, overload

from ome_types.model.ome_2016_06 import Annotation

from ._base_type import OMEType

_T_co = TypeVar("_T_co", covariant=True) # Any type covariant containers.


class StructuredAnnotationsMixin(OMEType, Sequence[Annotation]): # type: ignore
def _iter_annotations(self) -> Iterable[Annotation]:
class StructuredAnnotationsMixin(OMEType, Sequence[Annotation]):
def _iter_annotations(self) -> Iterator[Annotation]:
for x in self.__fields__.values():
if issubclass(x.type_, Annotation):
yield from getattr(self, x.name)
Expand All @@ -26,3 +24,6 @@ def __getitem__(self, key: int | slice) -> Annotation | Sequence[Annotation]:

def __len__(self) -> int:
return len(list(self._iter_annotations()))

def __iter__(self) -> Iterator[Annotation]:
return self._iter_annotations()

0 comments on commit a5940d1

Please sign in to comment.