Update pyright config and fix/silence errors
Committed 140362
--- a/pyproject.toml
+++ b/pyproject.toml
authors = ["Angelo Gladding <angelo@ragt.ag>"]
license = "BSD-2-Clause"
+[tool.pyright]
+reportGeneralTypeIssues = false
+reportOptionalMemberAccess = false
+reportUnboundVariable = false
+
[[tool.poetry.source]]
name = "main"
url = "https://ragt.ag/code/pypi"
index ed8fdde..0000000
--- a/pyrightconfig.json
-{
- "reportGeneralTypeIssues": false
-}
--- a/sqlyte.py
+++ b/sqlyte.py
import os
import pathlib
-import pendulum
+import pendulum.parser as pendulum
+from pendulum.datetime import DateTime
try:
- from pysqlite3 import dbapi2 as sqlite3
+ from pysqlite3 import dbapi2 as sqlite3 # type: ignore
except (ImportError, NameError): # NOTE pysqlite3.dbapi2 raises NameError
logging.info("falling back to sqlite3 in the standard library")
import sqlite3
+try:
+ from web import slrzd # type: ignore
+except ImportError:
+ slrzd = None
+
+
__all__ = ["IntegrityError", "OperationalError", "ProgrammingError", "db"]
IntegrityError = sqlite3.IntegrityError
sqlite3.register_converter("DATETIME", from_datetime)
-sqlite3.register_adapter(pendulum.DateTime, lambda val: val.isoformat(" "))
+sqlite3.register_adapter(DateTime, lambda val: val.isoformat(" "))
def from_json(val):
class JSONEncoder(json.JSONEncoder):
- def default(self, obj):
- # XXX if isinstance(obj, uri.URI):
- # XXX return str(obj)
- if isinstance(obj, (datetime.date, datetime.datetime)):
- obj = pendulum.instance(obj)
+ def default(self, o):
+ # XXX if isinstance(o, uri.URI):
+ # XXX return str(o)
+ if isinstance(o, (datetime.date, datetime.datetime)):
+ o = pendulum.instance(o)
return {
- "datetime": obj.in_timezone("UTC").isoformat(),
- "timezone": obj.tzinfo.name,
+ "datetime": o.in_timezone("UTC").isoformat(),
+ "timezone": o.tzinfo.name,
}
- return json.JSONEncoder.default(self, obj)
+ return json.JSONEncoder.default(self, o)
sqlite3.register_converter("JSON", from_json)
self.cur.execute(sql)
class Results:
- def __init__(innerself, results):
- innerself.results = list(results)
+ def __init__(self, results):
+ self.results = list(results)
- def pop(innerself, index):
- return innerself.results.pop(index)
+ def pop(self, index):
+ return self.results.pop(index)
- def __getitem__(innerself, index):
- return innerself.results[index]
+ def __getitem__(self, index):
+ return self.results[index]
- def __len__(innerself):
- return len(innerself.results)
+ def __len__(self):
+ return len(self.results)
- def _repr_html_(innerself):
+ def _repr_html_(innerself): # type: ignore
results = "<tr>"
types = {}
for column in self.columns(table):
results += "<tr>"
for key, value in dict(result).items():
if types[key] == "JSON":
- encoded_json = JSONEncoder(indent=2).encode(value)
- value = solarized.highlight(encoded_json, ".json")
+ value = JSONEncoder(indent=2).encode(value)
+ if slrzd:
+ value = slrzd.highlight(value, ".json")
results += f"<td>{value}</td>"
results += "</tr>"
return f"<table>{results}</table>"