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

remove numbers module #8

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
11 changes: 5 additions & 6 deletions src/CynanBot/misc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import random
import re
from datetime import datetime
from numbers import Number
from typing import Any, Dict, Generator, List, Optional, Pattern
from urllib.parse import urlparse

Expand Down Expand Up @@ -152,7 +151,7 @@ def getBoolFromDict(d: Optional[Dict[str, Any]], key: str, fallback: Optional[bo
raise KeyError(f'there is no fallback and key \"{key}\" doesn\'t exist in d: \"{d}\"')

if not isValidBool(value):
if isinstance(value, Number):
if isinstance(value, (float, int)):
value = numToBool(value)
elif isinstance(value, str):
value = strToBool(value)
Expand Down Expand Up @@ -337,11 +336,11 @@ def hasItems(l: Optional[Any]) -> bool:
def isValidBool(b: Optional[bool]) -> bool:
return b is not None and isinstance(b, bool)

def isValidInt(i: Optional[Number]) -> bool:
def isValidInt(i: Optional[float]) -> bool:
return isValidNum(i) and isinstance(i, int)

def isValidNum(n: Optional[Number]) -> bool:
return n is not None and isinstance(n, Number) and math.isfinite(n)
def isValidNum(n: Optional[float]) -> bool:
return n is not None and isinstance(n, (float, int)) and math.isfinite(n)

def isValidStr(s: Optional[str]) -> bool:
return s is not None and isinstance(s, str) and len(s) >= 1 and not s.isspace()
Expand All @@ -358,7 +357,7 @@ def isValidUrl(s: Optional[str]) -> bool:

return False

def numToBool(n: Optional[Number]) -> bool:
def numToBool(n: Optional[float]) -> bool:
if not isValidNum(n):
raise ValueError(f'n argument is malformed: \"{n}\"')

Expand Down