Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove PostgreSQL's UUID support #95
Conversation
|
While this fixes your particular use case - it will break stuff for other people. Now all UUID fields on a model will be an union of I think the right solution here is to extend mypy plugin. |
|
I wonder if it would be possible to use an overloaded function with literal types to fix this? Maybe something like |
|
Interesting, I actually tried something like this and remember it didn't
work. Maybe I did something wrong.
…On Fri, Jul 26, 2019 at 1:59 PM Jukka Lehtosalo ***@***.***> wrote:
I wonder if it would be possible to use an overloaded function with
literal types to fix this? Maybe something like subprocess.Popen:
https://github.com/python/typeshed/blob/master/stdlib/3/subprocess.pyi#L809
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#95?email_source=notifications&email_token=AAHASBEHQ2GWFRDBIQKRTZ3QBLRKZA5CNFSM4IGY2EBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD24L6VQ#issuecomment-515424086>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHASBB5ZCNZYVZALMINUYDQBLRKZANCNFSM4IGY2EBA>
.
|
|
I think we should try what @JukkaL proposes, using a union in this context may cause many false positives. |
It seems I took too long to reply and this line moved? Otherwise I don't see how line 809 of current master relates to this. I guess this is what you had in mind? https://github.com/python/typeshed/blob/3ad3ed82c75b4fb82f71f5500b50f18a98f12f49/stdlib/3/subprocess.pyi#L809 I just tried the following: diff --git a/sqlalchemy-stubs/dialects/postgresql/base.pyi b/sqlalchemy-stubs/dialects/postgresql/base.pyi
index d910e5c..2c6917f 100644
--- a/sqlalchemy-stubs/dialects/postgresql/base.pyi
+++ b/sqlalchemy-stubs/dialects/postgresql/base.pyi
@@ -1,8 +1,9 @@
from ... import schema
from ...engine import default, reflection
from ...sql import compiler, expression, sqltypes, type_api
-from typing import Any, Optional, Set, Type, Text, Pattern, Dict
+from typing import Any, Optional, Set, Type, Text, Pattern, Dict, overload
from datetime import timedelta
+import uuid
from sqlalchemy.types import INTEGER as INTEGER, BIGINT as BIGINT, SMALLINT as SMALLINT, VARCHAR as VARCHAR, \
CHAR as CHAR, TEXT as TEXT, FLOAT as FLOAT, NUMERIC as NUMERIC, \
@@ -66,12 +67,20 @@ class BIT(sqltypes.TypeEngine[str]):
def __init__(self, length: Optional[int] = ..., varying: bool = ...) -> None: ...
PGBit = BIT
+@overload
class UUID(sqltypes.TypeEngine[str]):
__visit_name__: str = ...
as_uuid: bool = ...
def __init__(self, as_uuid: bool = ...) -> None: ...
def bind_processor(self, dialect: Any): ...
def result_processor(self, dialect: Any, coltype: Any): ...
+@overload
+class UUID(sqltypes.TypeEngine[uuid.UUID]):
+ __visit_name__: str = ...
+ as_uuid: bool = ...
+ def __init__(self, as_uuid: bool = ...) -> None: ...
+ def bind_processor(self, dialect: Any): ...
+ def result_processor(self, dialect: Any, coltype: Any): ...
PGUuid = UUID
class TSVECTOR(sqltypes.TypeEngine[str]):However that doesn't work (same error message as #94). It seems |
|
You need to overload the constructor, not the class itself. |
bochecha commentedJul 25, 2019
SQLAlchemy allows setting UUID columns to either a string representation
of a UUID (e.g '46260785-9b7e-4a59-824f-af994a510673') or to a Python
uuid.UUID object.
Fixes #94