Remove `BaseModel` use from all dataclass-like uses

drop_pydantic
Tyler Goodlet 2022-07-06 12:54:03 -04:00
parent 4ff1090284
commit c870665be0
6 changed files with 20 additions and 37 deletions

View File

@ -32,7 +32,6 @@ from typing import (
)
import pendulum
from pydantic import BaseModel
import trio
import tractor
import wsproto
@ -47,6 +46,7 @@ from piker.clearing._messages import (
BrokerdPosition,
BrokerdStatus,
)
from pikerd.data.types import Struct
from . import log
from .api import (
Client,
@ -62,7 +62,7 @@ from .feed import (
)
class Trade(BaseModel):
class Trade(Struct):
'''
Trade class that helps parse and validate ownTrades stream

View File

@ -26,7 +26,6 @@ import time
from typing import AsyncIterator, Callable
from bidict import bidict
from pydantic import BaseModel
import trio
from trio_typing import TaskStatus
import tractor
@ -34,6 +33,7 @@ import tractor
from ..log import get_logger
from ..data._normalize import iterticks
from ..data.feed import Feed, maybe_open_feed
from ..data.types import Struct
from .._daemon import maybe_spawn_brokerd
from . import _paper_engine as paper
from ._messages import (
@ -303,7 +303,7 @@ class TradesRelay:
consumers: int = 0
class Router(BaseModel):
class Router(Struct):
'''
Order router which manages and tracks per-broker dark book,
alerts, clearing and related data feed management.
@ -324,10 +324,6 @@ class Router(BaseModel):
# brokername to trades-dialogues streams with ``brokerd`` actors
relays: dict[str, TradesRelay] = {}
class Config:
arbitrary_types_allowed = True
underscore_attrs_are_private = False
def get_dark_book(
self,
brokername: str,

View File

@ -42,7 +42,6 @@ from trio_typing import TaskStatus
import trimeter
import tractor
from tractor.trionics import maybe_open_context
from pydantic import BaseModel
import pendulum
import numpy as np
@ -59,6 +58,7 @@ from ._sharedmem import (
ShmArray,
)
from .ingest import get_ingestormod
from .types import Struct
from ._source import (
base_iohlc_dtype,
Symbol,
@ -84,7 +84,7 @@ if TYPE_CHECKING:
log = get_logger(__name__)
class _FeedsBus(BaseModel):
class _FeedsBus(Struct):
'''
Data feeds broadcaster and persistence management.
@ -100,10 +100,6 @@ class _FeedsBus(BaseModel):
a dedicated cancel scope.
'''
class Config:
arbitrary_types_allowed = True
underscore_attrs_are_private = False
brokername: str
nursery: trio.Nursery
feeds: dict[str, tuple[dict, dict]] = {}

View File

@ -21,7 +21,6 @@ Qt event proxying and processing using ``trio`` mem chans.
from contextlib import asynccontextmanager, AsyncExitStack
from typing import Callable
from pydantic import BaseModel
import trio
from PyQt5 import QtCore
from PyQt5.QtCore import QEvent, pyqtBoundSignal
@ -30,6 +29,8 @@ from PyQt5.QtWidgets import (
QGraphicsSceneMouseEvent as gs_mouse,
)
from ..data.types import Struct
MOUSE_EVENTS = {
gs_mouse.GraphicsSceneMousePress,
@ -43,13 +44,10 @@ MOUSE_EVENTS = {
# TODO: maybe consider some constrained ints down the road?
# https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
class KeyboardMsg(BaseModel):
class KeyboardMsg(Struct):
'''Unpacked Qt keyboard event data.
'''
class Config:
arbitrary_types_allowed = True
event: QEvent
etype: int
key: int
@ -57,16 +55,13 @@ class KeyboardMsg(BaseModel):
txt: str
def to_tuple(self) -> tuple:
return tuple(self.dict().values())
return tuple(self.to_dict().values())
class MouseMsg(BaseModel):
class MouseMsg(Struct):
'''Unpacked Qt keyboard event data.
'''
class Config:
arbitrary_types_allowed = True
event: QEvent
etype: int
button: int

View File

@ -22,12 +22,9 @@ from __future__ import annotations
from typing import (
Optional, Generic,
TypeVar, Callable,
Literal,
)
import enum
import sys
from pydantic import BaseModel, validator
# from pydantic import BaseModel, validator
from pydantic.generics import GenericModel
from PyQt5.QtWidgets import (
QWidget,
@ -38,6 +35,7 @@ from ._forms import (
# FontScaledDelegate,
Edit,
)
from ..data.types import Struct
DataType = TypeVar('DataType')
@ -62,7 +60,7 @@ class Selection(Field[DataType], Generic[DataType]):
options: dict[str, DataType]
# value: DataType = None
@validator('value') # , always=True)
# @validator('value') # , always=True)
def set_value_first(
cls,
@ -100,7 +98,7 @@ class Edit(Field[DataType], Generic[DataType]):
widget_factory = Edit
class AllocatorPane(BaseModel):
class AllocatorPane(Struct):
account = Selection[str](
options=dict.fromkeys(

View File

@ -27,7 +27,6 @@ import time
from typing import Optional, Dict, Callable, Any
import uuid
from pydantic import BaseModel
import tractor
import trio
from PyQt5.QtCore import Qt
@ -41,6 +40,7 @@ from ..clearing._allocate import (
from ._style import _font
from ..data._source import Symbol
from ..data.feed import Feed
from ..data.types import Struct
from ..log import get_logger
from ._editors import LineEditor, ArrowEditor
from ._lines import order_line, LevelLine
@ -58,7 +58,7 @@ from ._forms import open_form_input_handling
log = get_logger(__name__)
class OrderDialog(BaseModel):
class OrderDialog(Struct):
'''
Trade dialogue meta-data describing the lifetime
of an order submission to ``emsd`` from a chart.
@ -73,10 +73,6 @@ class OrderDialog(BaseModel):
msgs: dict[str, dict] = {}
fills: Dict[str, Any] = {}
class Config:
arbitrary_types_allowed = True
underscore_attrs_are_private = False
def on_level_change_update_next_order_info(
@ -858,7 +854,9 @@ async def process_trades_and_update_ui(
# delete level line from view
mode.on_cancel(oid)
broker_msg = msg['brokerd_msg']
log.warning(f'Order {oid} failed with:\n{pformat(broker_msg)}')
log.warning(
f'Order {oid} failed with:\n{pformat(broker_msg)}'
)
elif resp in (
'dark_triggered'