-
Notifications
You must be signed in to change notification settings - Fork 0
Better static analysis support #19
base: main
Are you sure you want to change the base?
Conversation
@@ -39,18 +54,18 @@ | |||
from pynocular.nested_database_model import NestedDatabaseModel | |||
|
|||
|
|||
def is_valid_uuid(string: str) -> bool: | |||
"""Check if a string is a valid UUID | |||
def is_valid_uuid(obj: Any) -> TypeGuard["UUID_STR"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does TypeGuard
do? The return here is still bool
|
||
The false positives are due to a limitation of python's type hint system that | ||
doesn't allow for dynamic class modification. The current workaround is to use | ||
the `BaseModel_database_model_hint` class provided by Pynocular, which is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That class name doesn't follow Python convention and is also very wordy. We shouldn't have to do this in order get mypy to work. If the issue is the dynamic class modification we should look into fixing that first before patching over it
pynocular/database_model.py
Outdated
return str(v) | ||
else: | ||
raise ValueError("invalid UUID string") | ||
|
||
|
||
SelfType = TypeVar("SelfType", bound="DatabaseModel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the purpose of this? A comment would be helpful
other: int = 0 | ||
|
||
class NestedModel(DatabaseModel, table_name = "table2", database_info=DBInfo("type")): | ||
if TYPE_CHECKING: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a way to get the nested models to have type checking/IDE support, but it's not needed if you don't care about that
Overview of changes