Skip to content

Commit

Permalink
fix some LGTM/CodeQL warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabu committed Apr 11, 2022
1 parent 356baff commit 1e8185f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 2 additions & 4 deletions pdfannots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# This script, which is not part of the pdfannots package, allows pdfannots
# to by run directly from a source tree clone.

import sys
from pdfannots.cli import main

if __name__ == '__main__':
sys.exit(main())
import pdfannots.cli
pdfannots.cli.main()
26 changes: 21 additions & 5 deletions pdfannots/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bisect
import datetime
import enum
import functools
import logging
import typing

Expand Down Expand Up @@ -94,6 +95,7 @@ def square_of_distance_to_closest_point(self, point: Point) -> float:
return abs(px - x)**2 + abs(py - y)**2


@functools.total_ordering
class Page:
"""
Page.
Expand All @@ -110,7 +112,7 @@ class Page:
def __init__(
self,
pageno: int,
objid: typing.Any,
objid: object,
label: typing.Optional[str],
mediabox: BoxCoords,
fixed_columns: typing.Optional[int] = None
Expand All @@ -135,17 +137,18 @@ def __str__(self) -> str:
# + 1 for 1-based page numbers in normal program output (error messages, etc.)
return 'page #%d' % (self.pageno + 1)

def __eq__(self, other: typing.Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Page):
return NotImplemented
return self.pageno == other.pageno

def __lt__(self, other: typing.Any) -> bool:
def __lt__(self, other: object) -> bool:
if not isinstance(other, Page):
return NotImplemented
return self.pageno < other.pageno


@functools.total_ordering
class Pos:
"""
A position within the document.
Expand All @@ -168,7 +171,14 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return '<Pos pg#%d (%.3f,%.3f) #%d>' % (self.page.pageno, self.x, self.y, self._pageseq)

def __lt__(self, other: typing.Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Pos):
return (self.page == other.page
and self.x == other.x
and self.y == other.y)
return NotImplemented

def __lt__(self, other: object) -> bool:
if isinstance(other, Pos):
if self.page == other.page:
assert self.page is other.page
Expand Down Expand Up @@ -216,13 +226,19 @@ def update_pageseq(self, component: LTComponent, pageseq: int) -> None:
self._pageseq_distance = d


@functools.total_ordering
class ObjectWithPos:
"""Any object that (eventually) has a logical position on the page."""

def __init__(self, pos: typing.Optional[Pos] = None):
self.pos = pos

def __lt__(self, other: typing.Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, ObjectWithPos):
return self.pos == other.pos
return NotImplemented

def __lt__(self, other: object) -> bool:
if isinstance(other, ObjectWithPos):
assert self.pos is not None
assert other.pos is not None
Expand Down

0 comments on commit 1e8185f

Please sign in to comment.