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

feat: Add type hint on Quote #396

Merged
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
4 changes: 2 additions & 2 deletions stock_indicators/_cstypes/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class DateTime:
>>> cs_now
3/26/2021 10:02:22 PM
"""
def __new__(cls, datetime) -> CsDateTime:
def __new__(cls, datetime: PyDateTime) -> CsDateTime:
return CsDateTime.Parse(datetime.isoformat())


def to_pydatetime(cs_datetime):
def to_pydatetime(cs_datetime: CsDateTime) -> PyDateTime:
"""
Converts C#'s `System.DateTime` struct to a native Python datetime object.

Expand Down
4 changes: 2 additions & 2 deletions stock_indicators/_cstypes/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Decimal:
Class for converting a number into C#'s `System.Decimal` class.

Parameters:
decimal : `int`, `float` or any `object` that can be represented as a number.
decimal : `int`, `float` or any `object` that can be represented as a number string.

Example:
Constructing `System.Decimal` from `float` of Python.
Expand All @@ -22,7 +22,7 @@ def __new__(cls, decimal) -> CsDecimal:
return CsDecimal.Parse(str(decimal), CsCultureInfo.InvariantCulture)


def to_pydecimal(cs_decimal):
def to_pydecimal(cs_decimal: CsDecimal) -> PyDecimal:
"""
Converts an object to a native Python decimal object.

Expand Down
18 changes: 11 additions & 7 deletions stock_indicators/indicators/common/quote.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from datetime import datetime
from decimal import Decimal
from typing import Iterable
from typing import Any, Iterable, Optional

from stock_indicators._cslib import CsQuote
from stock_indicators._cslib import CsQuoteUtility
from stock_indicators._cslib import CsQuote, CsQuoteUtility
from stock_indicators._cstypes import List as CsList
from stock_indicators._cstypes import DateTime as CsDateTime
from stock_indicators._cstypes import Decimal as CsDecimal
from stock_indicators._cstypes.datetime import to_pydatetime
from stock_indicators._cstypes.decimal import to_pydecimal
from stock_indicators._cstypes import to_pydatetime, to_pydecimal
from stock_indicators.indicators.common.enums import CandlePart
from stock_indicators.indicators.common._contrib.type_resolver import generate_cs_inherited_class

Expand Down Expand Up @@ -56,7 +55,9 @@
close = property(_get_close, _set_close)
volume = property(_get_volume, _set_volume)

def __init__(self, date, open = None, high = None, low = None, close = None, volume = None):
def __init__(self, date: datetime, open: Optional[Any] = None,

Check warning on line 58 in stock_indicators/indicators/common/quote.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

stock_indicators/indicators/common/quote.py#L58

Redefining built-in 'open'
high: Optional[Any] = None, low: Optional[Any] = None,
DaveSkender marked this conversation as resolved.
Show resolved Hide resolved
close: Optional[Any] = None, volume: Optional[Any] = None):
self.date = date
self.open: Decimal = open if open else 0
self.high: Decimal = high if high else 0
Expand Down Expand Up @@ -86,4 +87,7 @@


class Quote(generate_cs_inherited_class(_Quote, CsQuote)):
"""A single dated quote containing OHLCV elements."""
"""
A single dated quote containing OHLCV elements.
OHLCV values can be given as any object that can be represented as a number string.
"""
Loading