Skip to content
Open
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
26 changes: 1 addition & 25 deletions lumibot/entities/asset.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
from collections import UserDict
from datetime import date, datetime
from enum import Enum

from lumibot.tools import parse_symbol


# Custom string enum implementation for Python 3.9 compatibility
class StrEnum(str, Enum):
"""
A string enum implementation that works with Python 3.9+

This class extends str and Enum to create string enums that:
1. Can be used like strings (string methods, comparison)
2. Are hashable (for use in dictionaries, sets, etc.)
3. Can be used in string comparisons without explicit conversion
"""
def __str__(self):
return self.value

def __eq__(self, other):
if isinstance(other, str):
return self.value == other
return super().__eq__(other)

def __hash__(self):
# Use the hash of the enum member, not the string value
# This ensures proper hashability while maintaining enum identity
return super().__hash__()
from lumibot.tools.types import StrEnum


class Asset:
Expand Down
28 changes: 1 addition & 27 deletions lumibot/entities/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,12 @@
import uuid
from collections import namedtuple
from decimal import Decimal
from enum import Enum
from threading import Event
import datetime
from typing import Union

import lumibot.entities as entities
from lumibot.tools.types import check_positive, check_price


# Custom string enum implementation for Python 3.9 compatibility
class StrEnum(str, Enum):
"""
A string enum implementation that works with Python 3.9+

This class extends str and Enum to create string enums that:
1. Can be used like strings (string methods, comparison)
2. Are hashable (for use in dictionaries, sets, etc.)
3. Can be used in string comparisons without explicit conversion
"""
def __str__(self):
return self.value

def __eq__(self, other):
if isinstance(other, str):
return self.value == other
return super().__eq__(other)

def __hash__(self):
# Use the hash of the enum member, not the string value
# This ensures proper hashability while maintaining enum identity
return super().__hash__()

from lumibot.tools.types import check_positive, check_price, StrEnum

SELL = "sell"
BUY = "buy"
Expand Down
23 changes: 23 additions & 0 deletions lumibot/tools/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import warnings
from enum import Enum
from decimal import Decimal

# Custom string enum implementation for Python 3.9 compatibility
class StrEnum(str, Enum):
"""
A string enum implementation that works with Python 3.9+

This class extends str and Enum to create string enums that:
1. Can be used like strings (string methods, comparison)
2. Are hashable (for use in dictionaries, sets, etc.)
3. Can be used in string comparisons without explicit conversion
"""
def __str__(self):
return self.value

def __eq__(self, other):
if isinstance(other, str):
return self.value == other
return super().__eq__(other)

def __hash__(self):
# Use the hash of the enum member, not the string value
# This ensures proper hashability while maintaining enum identity
return super().__hash__()

def check_numeric(
input, type, error_message, positive=True, strict=False, nullable=False, ratio=False, allow_negative=True
Expand Down
Loading