Skip to content

Commit

Permalink
Fix some typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 13, 2023
1 parent 0156d8e commit 487e953
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions c2cgeoform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any, Tuple, Union

import pyramid.config
from deform import Form, widget
Expand All @@ -16,7 +16,7 @@


""" Default search paths for the form templates. """
default_search_paths = (
default_search_paths: Tuple[str, ...] = (
resource_filename("c2cgeoform", "templates/widgets"),
resource_filename("deform", "templates"),
)
Expand Down
14 changes: 12 additions & 2 deletions c2cgeoform/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ def deferred_dbsession(node: Any, kwargs: dict[str, Any]) -> sqlalchemy.orm.Sess
return cast(sqlalchemy.orm.Session, kwargs.get("dbsession"))


def unique_validator(mapper: type[Any], column: str, id_column: str, node: str, value: Any) -> None:
def unique_validator(
mapper: type[Any],
column: sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
id_column: sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
node: str,
value: Any,
) -> None:
dbsession: sqlalchemy.orm.Session = node.bindings["dbsession"] # type: ignore[attr-defined]
_id = node.bindings["request"].matchdict["id"] # type: ignore[attr-defined]
_id = _id if _id != "new" else None
Expand Down Expand Up @@ -58,7 +64,11 @@ def __init__(self, *args: Any, **kw: Any) -> None:
self.request = deferred_request
self.dbsession = deferred_dbsession

def add_unique_validator(self, column: sqlalchemy.sql.elements.NamedColumn[Any], column_id: str) -> None:
def add_unique_validator(
self,
column: sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
column_id: sqlalchemy.orm.attributes.InstrumentedAttribute[Any],
) -> None:
"""
Adds an unique validator on this schema instance.
Expand Down
14 changes: 8 additions & 6 deletions c2cgeoform/views/abstract_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Callable, Generic, Optional, TypedDict, TypeVar, Union, cast
from typing import Any, Callable, Dict, Generic, Optional, TypedDict, TypeVar, Union, cast

import geojson
import pyramid.request
Expand Down Expand Up @@ -229,9 +229,11 @@ class _Index(TypedDict):


class AbstractViews(Generic[T]):
_model = None # sqlalchemy model
_model: Optional[type[T]] = None # sqlalchemy model
_list_fields: list[ListField[T]] = [] # Fields in list
_list_ordered_fields: list[sqlalchemy.schema.Column[Any]] = [] # Fields in list used for default orderby
_list_ordered_fields: list[
Union[sqlalchemy.sql.elements.ColumnClause[Any], sqlalchemy.sql.elements.ColumnElement[Any]]
] = [] # Fields in list used for default orderby
_id_field: Optional[str] = None # Primary key
_geometry_field: Optional[str] = None # Geometry field
_base_schema: Optional[type[T]] = None # base colander schema
Expand All @@ -244,8 +246,8 @@ class AbstractViews(Generic[T]):
def __init__(self, request: pyramid.request.Request) -> None:
self._request = request
self._schema: Optional[str] = None
self._appstruct: Optional[str] = None
self._obj: Optional[type[T]] = None
self._appstruct: Optional[Dict[str, Any]] = None
self._obj: Optional[T] = None

def index(self) -> _Index:
return {
Expand Down Expand Up @@ -571,7 +573,7 @@ def save(self) -> Union[JSONDict, pyramid.response.Response]:
self._request.route_url(
"c2cgeoform_item",
action="edit",
id=self._obj.__getattribute__(self._id_field), # type: ignore[call-arg,arg-type] # pylint: disable=unnecessary-dunder-call
id=self._obj.__getattribute__(self._id_field), # type: ignore[arg-type] # pylint: disable=unnecessary-dunder-call
_query=[("msg_col", "submit_ok")],
)
)
Expand Down

0 comments on commit 487e953

Please sign in to comment.