satisfy linter and type checker in many places
This commit is contained in:
parent
9d21f8c933
commit
fb4da7c768
16 changed files with 38 additions and 26 deletions
|
@ -68,7 +68,7 @@ class APIRoot(GenericAPIView):
|
|||
@cached_property
|
||||
def urls(self):
|
||||
include_editor = can_access_editor(self.request)
|
||||
urls = OrderedDict()
|
||||
urls: dict[str, dict[str, str] | str] = OrderedDict()
|
||||
for urlpattern in router.urls:
|
||||
if not include_editor and inspect.getmodule(urlpattern.callback).__name__.startswith('c3nav.editor.'):
|
||||
continue
|
||||
|
|
|
@ -643,7 +643,7 @@ def graph_edit(request, level=None, space=None):
|
|||
'obj_title': node.title
|
||||
})
|
||||
|
||||
permissions = AccessPermission.get_for_request(request) | set([None])
|
||||
permissions = AccessPermission.get_for_request(request) | {None}
|
||||
edge_settings_form = GraphEdgeSettingsForm(instance=GraphEdge(), request=request, data=request.POST)
|
||||
graph_action_form = GraphEditorActionForm(request=request, allow_clicked_position=create_nodes,
|
||||
data=request.POST)
|
||||
|
|
|
@ -475,7 +475,7 @@ class BaseQueryWrapper(BaseWrapper):
|
|||
if not segments:
|
||||
# if the check is just 'pk' or the name or the name of the primary key, return the mathing object
|
||||
if is_created_pk(filter_value):
|
||||
return Q(pk__in=()), set([filter_value])
|
||||
return Q(pk__in=()), {filter_value}
|
||||
if filter_value is None or int(filter_value) in self._changeset.deleted_existing.get(model, ()):
|
||||
return Q(pk__in=()), set()
|
||||
return q, set()
|
||||
|
|
|
@ -213,7 +213,7 @@ class AccessPermission(models.Model):
|
|||
access_restriction_ids = set(permissions.keys())
|
||||
|
||||
expire_date = min((e for e in permissions.values() if e), default=timezone.now()+timedelta(seconds=120))
|
||||
cache.set(cache_key, access_restriction_ids, max(0, (expire_date-timezone.now()).total_seconds()))
|
||||
cache.set(cache_key, access_restriction_ids, max(0.0, (expire_date-timezone.now()).total_seconds()))
|
||||
return set(access_restriction_ids)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -343,8 +343,10 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
|||
csgraph[area.tmpid, connected_tmpid] = True
|
||||
|
||||
repeat = True
|
||||
|
||||
while repeat:
|
||||
repeat = False
|
||||
# noinspection PyTupleAssignmentBalance
|
||||
distances, predecessors = dijkstra(csgraph, directed=False, return_predecessors=True, unweighted=True)
|
||||
np_areas_with_altitude = np.array(areas_with_altitude, dtype=np.uint32)
|
||||
relevant_distances = distances[np_areas_with_altitude[:, None], np_areas_with_altitude]
|
||||
|
|
|
@ -19,7 +19,7 @@ class AbstractOpenScadElem(ABC):
|
|||
raise NotADirectoryError
|
||||
|
||||
|
||||
class AbstractOpenScadBlock(AbstractOpenScadElem, UserList):
|
||||
class AbstractOpenScadBlock(AbstractOpenScadElem, UserList, ABC):
|
||||
def render_children(self):
|
||||
return '\n'.join(child.render() for child in self.data if child is not None)
|
||||
|
||||
|
@ -290,6 +290,7 @@ class OpenSCADEngine(Base3DEngine):
|
|||
main_building_block.append(obstacles_block)
|
||||
|
||||
if self.min_width and geoms.on_top_of_id is None:
|
||||
# noinspection PyUnboundLocalVariable
|
||||
main_building_block_inner.append(
|
||||
self._add_polygon('min width',
|
||||
self._satisfy_min_width(buildings).intersection(self.bbox).buffer(0),
|
||||
|
|
|
@ -32,7 +32,7 @@ class MapRenderer:
|
|||
|
||||
def render(self, engine_cls, center=True):
|
||||
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
|
||||
access_permissions = self.access_permissions | set([None])
|
||||
access_permissions = self.access_permissions | {None}
|
||||
|
||||
bbox = prepared.prep(self.bbox)
|
||||
|
||||
|
|
4
src/c3nav/mapdata/utils/cache/indexed.py
vendored
4
src/c3nav/mapdata/utils/cache/indexed.py
vendored
|
@ -75,7 +75,7 @@ class GeometryIndexed:
|
|||
self._write_metadata(f)
|
||||
f.write(self.data.tobytes('C'))
|
||||
|
||||
def _write_metadata(cls, f):
|
||||
def _write_metadata(self, f):
|
||||
pass
|
||||
|
||||
def _get_geometry_bounds(self, geometry):
|
||||
|
@ -180,7 +180,9 @@ class GeometryIndexed:
|
|||
int(math.ceil((maxx-minx)/self.resolution))), dtype=np.uint8)
|
||||
|
||||
if self.data.size:
|
||||
# noinspection PyArgumentList
|
||||
minval = min(self.data.min(), 0)
|
||||
# noinspection PyArgumentList
|
||||
maxval = max(self.data.max(), minval+0.01)
|
||||
visible_data = ((self.data.astype(float)-minval)*255/(maxval-minval)).clip(0, 255).astype(np.uint8)
|
||||
image_data[self.y:self.y+height, self.x:self.x+width] = visible_data
|
||||
|
|
17
src/c3nav/mapdata/utils/cache/stats.py
vendored
17
src/c3nav/mapdata/utils/cache/stats.py
vendored
|
@ -59,16 +59,17 @@ fake_request = FakeRequest()
|
|||
|
||||
def convert_stats(stats):
|
||||
stats = [(name.split('__')[1:], value) for name, value in stats['data'].items()]
|
||||
result = {}
|
||||
result['locate'] = convert_locate(_filter_stats('locate', stats))
|
||||
result['location_retrieve'] = convert_location(_filter_stats('location_retrieve', stats))
|
||||
result['location_geometry'] = convert_location(_filter_stats('location_geometry', stats))
|
||||
result['route_origin'] = convert_location(
|
||||
result = {
|
||||
'locate': convert_locate(_filter_stats('locate', stats)),
|
||||
'location_retrieve': convert_location(_filter_stats('location_retrieve', stats)),
|
||||
'location_geometry': convert_location(_filter_stats('location_geometry', stats)),
|
||||
'route_origin': convert_location(
|
||||
(['pk'] + name, value) for name, value in _filter_stats('route_origin_', stats, startswith=True)
|
||||
)
|
||||
result['route_destination'] = convert_location(
|
||||
),
|
||||
'route_destination': convert_location(
|
||||
(['pk'] + name, value) for name, value in _filter_stats('route_destination_', stats, startswith=True)
|
||||
)
|
||||
),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ def triangulate_rings(rings, holes=None):
|
|||
|
||||
# remove triangles with no area
|
||||
facets = np.dstack((np.zeros(mesh_elements.shape), mesh_points[mesh_elements]))
|
||||
# noinspection PyArgumentList
|
||||
ok_index = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).max(axis=1) != 0
|
||||
mesh_elements = mesh_elements[ok_index]
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class MplPolygonPath(MplPathProxy):
|
|||
def shapely_to_mpl(geometry):
|
||||
"""
|
||||
convert a shapely Polygon or Multipolygon to a matplotlib Path
|
||||
:param polygon: shapely Polygon or Multipolygon
|
||||
:param geometry: shapely Polygon or Multipolygon
|
||||
:return: MplPathProxy
|
||||
"""
|
||||
if isinstance(geometry, Polygon):
|
||||
|
|
|
@ -81,7 +81,7 @@ def tile(request, level, zoom, x, y, access_permissions=None):
|
|||
access_permissions = parse_tile_access_cookie(cookie, settings.SECRET_TILE_KEY)
|
||||
access_permissions &= set(level_data.restrictions[minx:maxx, miny:maxy])
|
||||
else:
|
||||
access_permissions = set(int(i) for i in access_permissions.split('-')) - set([0])
|
||||
access_permissions = set(int(i) for i in access_permissions.split('-')) - {0}
|
||||
|
||||
# build cache keys
|
||||
last_update = level_data.history.last_update(minx, miny, maxx, maxy)
|
||||
|
|
|
@ -108,7 +108,7 @@ class LocatorStations:
|
|||
station = self.stations[station_id]
|
||||
station.frequencies.add(frequency)
|
||||
elif create:
|
||||
station = LocatorStation(bssid, ssid, set((frequency, )))
|
||||
station = LocatorStation(bssid, ssid, {frequency})
|
||||
station_id = len(self.stations)
|
||||
self.stations_lookup[(bssid, None)] = station_id
|
||||
self.stations.append(station)
|
||||
|
|
|
@ -95,6 +95,7 @@ class Route:
|
|||
description = item.waytype.description
|
||||
if item.waytype.up_separate and item.edge.rise > 0:
|
||||
description = item.waytype.description_up
|
||||
# noinspection PyComparisonWithNone
|
||||
if (item.waytype.level_change_description != False and last_primary_level and
|
||||
((item.last_item and item.level != item.last_item.level) or
|
||||
item.level.on_top_of_id)): # != False because it's lazy
|
||||
|
@ -124,6 +125,7 @@ class Route:
|
|||
description = current_space.leave_descriptions.get(next_space.pk, None)
|
||||
if description is None:
|
||||
description = item.space.enter_description
|
||||
# noinspection PyComparisonWithNone
|
||||
if description == None: # could be a lazy None
|
||||
description = _('Go to %(space_title)s.') % {'space_title': item.space.title}
|
||||
|
||||
|
@ -140,7 +142,9 @@ class Route:
|
|||
if item.edge:
|
||||
remaining_distance += item.edge.distance
|
||||
if remaining_distance:
|
||||
item.descriptions.append(('more_vert', _('%d m remaining to your destination.') % max(remaining_distance, 1)))
|
||||
item.descriptions.append(
|
||||
('more_vert', _('%d m remaining to your destination.') % max(remaining_distance, 1))
|
||||
)
|
||||
|
||||
items[-1].descriptions.append(('done', _('You have reached your destination.')))
|
||||
|
||||
|
@ -240,6 +244,5 @@ class RouteItem:
|
|||
return result
|
||||
|
||||
|
||||
|
||||
class NoRoute:
|
||||
distance = np.inf
|
||||
|
|
|
@ -38,6 +38,7 @@ class AtPositionConverter:
|
|||
|
||||
|
||||
class ConditionalConverter:
|
||||
# noinspection PyMethodOverriding
|
||||
def __init_subclass__(cls, /, name):
|
||||
cls.path = '%s/' % name
|
||||
cls.regex = '(%s/)?' % name
|
||||
|
|
|
@ -36,14 +36,15 @@ class ReportUpdateForm(ModelForm):
|
|||
('false', _('closed')),
|
||||
)
|
||||
|
||||
def save(self):
|
||||
def save(self, commit=True):
|
||||
with transaction.atomic():
|
||||
super().save()
|
||||
super().save(commit=commit)
|
||||
report = self.instance.report
|
||||
if self.instance.open is not None:
|
||||
report.open = self.instance.open
|
||||
if self.instance.assigned_to:
|
||||
report.assigned_to = self.instance.assigned_to
|
||||
if commit:
|
||||
report.save()
|
||||
|
||||
class Meta:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue