Skip to content

Commit

Permalink
Merge pull request #7884 from ckan/type-update-2023-10
Browse files Browse the repository at this point in the history
chore: update types
  • Loading branch information
wardi committed Nov 2, 2023
2 parents 665ca43 + 1248bf6 commit 8726efb
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ckan/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def ipython(namespace: Mapping[str, Any], banner: str) -> None:
from traitlets.config.loader import Config

c = Config()
c.TerminalInteractiveShell.banner2 = banner
setattr(c.TerminalInteractiveShell, "banner2", banner)

IPython.start_ipython([], user_ns=namespace, config=c)

Expand Down
8 changes: 5 additions & 3 deletions ckan/lib/dictization/model_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def relationship_list_save(
relationship_list.append(relationship)

def package_dict_save(
pkg_dict: dict[str, Any], context: Context,
pkg_dict: dict[str, Any], context: Context,
include_plugin_data: bool = False) -> 'model.Package':
model = context["model"]
package = context.get("package")
Expand All @@ -300,7 +300,7 @@ def package_dict_save(
if 'metadata_modified' in pkg_dict:
del pkg_dict['metadata_modified']

plugin_data = pkg_dict.pop('plugin_data', None)
plugin_data = pkg_dict.pop('plugin_data', None)
if include_plugin_data:
pkg_dict['plugin_data'] = copy.deepcopy(
plugin_data) if plugin_data else plugin_data
Expand Down Expand Up @@ -333,7 +333,9 @@ def group_member_save(context: Context, group_dict: dict[str, Any],
session = context["session"]
group = context['group']
assert group is not None
entity_list: list[dict[str, Any]] = group_dict.get(member_table_name, None)
entity_list: list[dict[str, Any]] | None = group_dict.get(
member_table_name, None
)

if entity_list is None:
if context.get('allow_partial_update', False):
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ def make_login_url(
parsed_base = urlparse(base)
netloc = parsed_base.netloc
parsed_base = parsed_base._replace(netloc=netloc, query=urlencode(md))
return cast(str, urlunparse(parsed_base))
return urlunparse(parsed_base)
return base


Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/lazyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __repr__(self):
return u'<LazyJSONObject %r>' % self._json_string
return u'<LazyJSONObject %r>' % self._json_dict

@property # type: ignore
@property
def encoded_json(self):
if self._json_string:
return self._json_string
Expand Down
6 changes: 3 additions & 3 deletions ckan/lib/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import mimetypes
from time import time
from typing import Any, Iterable, Optional, Tuple, Union, IO, cast
from typing import Any, Iterable, Optional, Tuple, Union, IO

from email.message import EmailMessage
from email import utils
Expand Down Expand Up @@ -75,9 +75,9 @@ def _mail_recipient(

for attachment in attachments:
if len(attachment) == 3:
name, _file, media_type = cast(AttachmentWithType, attachment)
name, _file, media_type = attachment
else:
name, _file = cast(AttachmentWithoutType, attachment)
name, _file = attachment
media_type = None

if not media_type:
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def user_list(

if all_fields:
for user in query.all():
result_dict = model_dictize.user_dictize(user[0], context)
result_dict: Any = model_dictize.user_dictize(user[0], context)
users_list.append(result_dict)
else:
for user in query.all():
Expand Down
6 changes: 3 additions & 3 deletions ckan/types/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from typing import TYPE_CHECKING, ClassVar, Type
from typing import TYPE_CHECKING, Any, ClassVar, Type
from typing_extensions import Protocol

from sqlalchemy.orm.scoping import ScopedSession
Expand Down Expand Up @@ -54,7 +54,7 @@ class Model(Protocol):
term_translation_table: ClassVar[Table]

Session: ClassVar[AlchemySession]
meta: ClassVar[Meta]
meta: ClassVar[Meta] | Any

repo: ClassVar["_model.Repository"]

Expand Down
16 changes: 10 additions & 6 deletions ckanext/datapusher/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ def datapusher_submit(context: Context, data_dict: dict[str, Any]):
r.raise_for_status()
except requests.exceptions.HTTPError as e:
m = 'An Error occurred while sending the job: {0}'.format(str(e))
try:
body = e.response.json()
if body.get('error'):
m += ' ' + body['error']
except ValueError:
body = e.response.text

body = ""
if e.response is not None:
try:
body = e.response.json()
if body.get('error'):
m += ' ' + body['error']
except ValueError:
body = e.response.text

error = {'message': m,
'details': body,
'status_code': r.status_code}
Expand Down
8 changes: 5 additions & 3 deletions ckanext/resourceproxy/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def proxy_resource(context: Context, data_dict: DataDict):
)

except requests.exceptions.HTTPError as error:
details = u'Could not proxy resource. Server responded with %s %s' % (
error.response.status_code, error.response.reason
)
details = 'Could not proxy resource.'
if error.response is not None:
details += ' Server responded with %s %s' % (
error.response.status_code, error.response.reason
)
return abort(409, detail=details)
except requests.exceptions.ConnectionError as error:
details = u'''Could not proxy resource because a
Expand Down
43 changes: 36 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ reportOptionalCall = true
reportOptionalIterable = true
reportOptionalContextManager = true
reportOptionalOperand = true
reportTypedDictNotRequiredAccess = false # We are using Context in a way that conflicts with this check
# We are using Context in a way that conflicts with this check
reportTypedDictNotRequiredAccess = false
reportConstantRedefinition = true
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = true
reportIncompatibleVariableOverride = false
reportOverlappingOverload = true
reportUntypedFunctionDecorator = false
reportUnknownParameterType = true
Expand Down

0 comments on commit 8726efb

Please sign in to comment.