Skip to content

Commit

Permalink
all ruff checks green
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanLukes committed Aug 27, 2024
1 parent d645b82 commit 5065687
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 138 deletions.
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"scikit-learn", # Machine learning
"scipy", # Scientific computing
"polars", # Data frames
# "pandas", # Data frames (not used, but needed for stubs in typings to not be Unknown)
# "pandas", # Data frames (not used, but needed for stubs in typings to not be Unknown)
"pandera", # Data validation
"pyarrow", # Columnar data format

Expand Down Expand Up @@ -166,6 +166,18 @@ pythonVersion = "3.12"
extend = "ruff_defaults.toml"
exclude = [".hatch", "scripts", "typings", "notebooks"]

[tool.ruff.lint.pylint]
allow-dunder-method-names = [
"__get_pydantic_core_schema__",
"__get_pydantic_json_schema__"
]

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S", "PLC1901", "PLC2701", "PLR2004", "PLR6301", "TID252"]

[tool.ruff.lint.isort]
known-first-party = ["renkon"]

# Coverage
# --------

Expand Down
2 changes: 2 additions & 0 deletions src/renkon/_internal/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import sys
from typing import override

from loguru import logger

Expand Down Expand Up @@ -48,6 +49,7 @@ def configure_logging(


class InterceptHandler(logging.Handler):
@override
def emit(self, record: logging.LogRecord) -> None:
# Get corresponding Loguru level if it exists.
level: str | int
Expand Down
107 changes: 0 additions & 107 deletions src/renkon/_internal/singleton.py

This file was deleted.

77 changes: 53 additions & 24 deletions src/renkon/core/model/type/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,63 +187,79 @@ def __get_pydantic_core_schema__(cls, source: type[BaseModel], handler: GetCoreS


class TopType(RenkonType):
def __init__(self, /, **data: Any) -> None:
if not data:
return
super().__init__(**data)

@override
def is_equal(self, other: RenkonType) -> bool:
return isinstance(other, TopType)

@override
def is_equivalent(self, other: RenkonType) -> bool:
return self.is_equal(other)

def is_subtype(self, other: RenkonType) -> bool: # noqa: ARG002
@override
def is_subtype(self, other: RenkonType) -> bool:
return False

@override
def is_supertype(self, other: RenkonType) -> bool:
return self.is_equal(other)

@override
def canonicalize(self) -> Self:
return self

@override
def normalize(self) -> RenkonType:
return self

@override
def dump_string(self) -> str:
return "any"

def __init__(self, /, **data: Any) -> None:
if not data:
return
super().__init__(**data)

@override
def __hash__(self) -> int:
return hash(TopType)


class BottomType(RenkonType):
def __init__(self, /, **data: Any) -> None:
if not data:
return
super().__init__(**data)

@override
def is_equal(self, other: RenkonType) -> bool:
return isinstance(other, BottomType)

@override
def is_equivalent(self, other: RenkonType) -> bool:
return self.is_equal(other)

def is_subtype(self, other: RenkonType) -> bool: # noqa: ARG002
@override
def is_subtype(self, other: RenkonType) -> bool:
return True

@override
def is_supertype(self, other: RenkonType) -> bool:
return self.is_equal(other)

@override
def canonicalize(self) -> Self:
return self

@override
def normalize(self) -> RenkonType:
return self

@override
def dump_string(self) -> str:
return "none"

def __init__(self, /, **data: Any) -> None:
if not data:
return
super().__init__(**data)

@override
def __hash__(self) -> int:
return hash(BottomType)

Expand Down Expand Up @@ -422,42 +438,55 @@ def __and__(self, other: UnionType) -> UnionType:
# region



# noinspection PyMethodMayBeStatic
class TreeToTypeTransformer(Transformer[RenkonType]):
def type(self, type_: list[RenkonType]):
@staticmethod
def type(type_: list[RenkonType]):
return type_[0]

def int(self, _) -> IntType:
@staticmethod
def int(_) -> IntType:
return int_()

def float(self, _) -> FloatType:
@staticmethod
def float(_) -> FloatType:
return float_()

def string(self, _) -> StringType:
@staticmethod
def string(_) -> StringType:
return str_()

def bool(self, _) -> BoolType:
@staticmethod
def bool(_) -> BoolType:
return bool_()

def top(self, _) -> RenkonType:
@staticmethod
def top(_) -> RenkonType:
return any_()

def bottom(self, _) -> BottomType:
@staticmethod
def bottom(_) -> BottomType:
return none()

def union(self, types: list[RenkonType]) -> UnionType:
@staticmethod
def union(types: list[RenkonType]) -> UnionType:
return union(*types)

def equatable(self, _) -> UnionType:
@staticmethod
def equatable(_) -> UnionType:
return equatable()

def comparable(self, _) -> UnionType:
@staticmethod
def comparable(_) -> UnionType:
return comparable()

def numeric(self, _) -> UnionType:
@staticmethod
def numeric(_) -> UnionType:
return numeric()

def paren(self, type_: list[RenkonType]) -> RenkonType:
@staticmethod
def paren(type_: list[RenkonType]) -> RenkonType:
return type_[0]


Expand Down
6 changes: 3 additions & 3 deletions src/renkon/core/trait/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import ClassVar, Protocol, final

import renkon.core.model.type as rk_type
from renkon.core.model import Schema, TraitId, TraitKind, TraitPattern, TraitSketch, TraitSpec
from renkon.core.model import TraitId, TraitKind, TraitPattern, TraitSketch, TraitSpec
from renkon.core.model.type import RenkonType


Expand Down Expand Up @@ -47,8 +47,8 @@ def typevars(self) -> dict[str, RenkonType]:
def typings(self) -> dict[str, RenkonType | str]:
return self.spec.typings

def can_sketch(self, _schema: Schema, _bindings: dict[str, str]) -> bool:
return False # TODO: implement
# def can_sketch(self, _schema: Schema, _bindings: dict[str, str]) -> bool:
# return False # TODO: implement

def sketch(self, **kwargs: RenkonType) -> TraitSketch:
return TraitSketch.model_validate(
Expand Down
4 changes: 1 addition & 3 deletions src/renkon/core/trait/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from abc import ABC
from typing import ClassVar, final

from renkon.core.model import RenkonType, TraitPattern, TraitSpec
from renkon.core.model import RenkonType, TraitKind, TraitPattern, TraitSpec
from renkon.core.trait.base import Trait


Expand All @@ -25,8 +25,6 @@ def __init_subclass__(cls, *, base_type: RenkonType | str, **kwargs: None):
if not isinstance(base_type, RenkonType):
base_type = RenkonType.model_validate(base_type)

from renkon.core.model import TraitKind

cls.spec = TraitSpec(
id=f"{cls.__qualname__}",
name=f"{cls.__name__}",
Expand Down

0 comments on commit 5065687

Please sign in to comment.