mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 04:44:26 +02:00
Fix for mypy issue, refs #503
This commit is contained in:
parent
7ca497a8f5
commit
c5d7ec1dd7
1 changed files with 7 additions and 2 deletions
|
|
@ -308,7 +308,6 @@ class Database:
|
||||||
assert (filename_or_conn is not None and (not memory and not memory_name)) or (
|
assert (filename_or_conn is not None and (not memory and not memory_name)) or (
|
||||||
filename_or_conn is None and (memory or memory_name)
|
filename_or_conn is None and (memory or memory_name)
|
||||||
), "Either specify a filename_or_conn or pass memory=True"
|
), "Either specify a filename_or_conn or pass memory=True"
|
||||||
self.conn = None
|
|
||||||
if memory_name:
|
if memory_name:
|
||||||
uri = "file:{}?mode=memory&cache=shared".format(memory_name)
|
uri = "file:{}?mode=memory&cache=shared".format(memory_name)
|
||||||
self.conn = sqlite3.connect(
|
self.conn = sqlite3.connect(
|
||||||
|
|
@ -320,7 +319,13 @@ class Database:
|
||||||
self.conn = sqlite3.connect(":memory:")
|
self.conn = sqlite3.connect(":memory:")
|
||||||
elif isinstance(filename_or_conn, (str, pathlib.Path)):
|
elif isinstance(filename_or_conn, (str, pathlib.Path)):
|
||||||
if recreate and os.path.exists(filename_or_conn):
|
if recreate and os.path.exists(filename_or_conn):
|
||||||
os.remove(filename_or_conn)
|
try:
|
||||||
|
os.remove(filename_or_conn)
|
||||||
|
except OSError:
|
||||||
|
# Avoid mypy and __repr__ errors, see:
|
||||||
|
# https://github.com/simonw/sqlite-utils/issues/503
|
||||||
|
self.conn = sqlite3.connect(":memory:")
|
||||||
|
raise
|
||||||
self.conn = sqlite3.connect(str(filename_or_conn))
|
self.conn = sqlite3.connect(str(filename_or_conn))
|
||||||
else:
|
else:
|
||||||
assert not recreate, "recreate cannot be used with connections, only paths"
|
assert not recreate, "recreate cannot be used with connections, only paths"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue