Skip to content

Commit

Permalink
Fix linting errors, mostly import sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmami committed Nov 14, 2023
1 parent b935d62 commit 1d2e8e0
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 110 deletions.
40 changes: 20 additions & 20 deletions penman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@
__version__,
__version_info__,
)
from penman.exceptions import (
PenmanError,
DecodeError,
)
from penman.tree import Tree
from penman.graph import (
Triple,
Graph,
)
from penman.layout import (
interpret,
configure,
from penman._format import (
format,
format_triples,
)
from penman._parse import (
parse,
iterparse,
parse,
parse_triples,
)
from penman._format import (
format,
format_triples,
)
from penman.codec import (
PENMANCodec,
_decode as decode,
_iterdecode as iterdecode,
_dump as dump,
_dumps as dumps,
_encode as encode,
_iterdecode as iterdecode,
_load as load,
_loads as loads,
_dump as dump,
_dumps as dumps,
)
from penman.exceptions import (
DecodeError,
PenmanError,
)
from penman.graph import (
Graph,
Triple,
)
from penman.layout import (
configure,
interpret,
)
from penman.tree import Tree
16 changes: 7 additions & 9 deletions penman/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
import sys
import os
import argparse
import json
import logging
import os
import sys

from penman import layout, transform
from penman.__about__ import __version__
from penman.model import Model
from penman import layout
from penman.codec import PENMANCodec
from penman import transform

from penman.model import Model

# Names of functions allowed for ordering triples/branches; we cannot
# resolve them to the actual functions until the model is loaded. If
Expand Down Expand Up @@ -108,13 +106,13 @@ def _check(g, model):
i = 1
errors = model.errors(g)
if errors:
for triple, errors in errors.items():
for triple, error_messages in errors.items():
if triple:
context = '({}) '.format(' '.join(map(str, triple)))
else:
context = ''
for error in errors:
g.metadata[f'error-{i}'] = context + error
for error_message in error_messages:
g.metadata[f'error-{i}'] = context + error_message
i += 1
return 1
else:
Expand Down
4 changes: 2 additions & 2 deletions penman/_format.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from typing import Optional, Union, List, Iterable
from typing import Iterable, List, Optional, Union

from penman.tree import Tree, is_atomic
from penman.types import BasicTriple
from penman.tree import (Tree, is_atomic)


def format(tree: Tree,
Expand Down
7 changes: 3 additions & 4 deletions penman/_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
Classes and functions for lexing PENMAN strings.
"""

from typing import Union, Iterable, Iterator, NamedTuple, Pattern, Optional
import re
import logging
import re
from typing import Iterable, Iterator, NamedTuple, Optional, Pattern, Union

from penman.exceptions import DecodeError


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -126,7 +125,7 @@ def expect(self, *choices):
try:
token = self.next()
except StopIteration:
raise self.error('Unexpected end of input')
raise self.error('Unexpected end of input') from None
if token.type not in choices:
raise self.error('Expected: {}'.format(', '.join(choices)),
token=token)
Expand Down
15 changes: 7 additions & 8 deletions penman/_parse.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@

from typing import Union, Iterable, Iterator, List
import logging
from typing import Iterable, Iterator, List, Union

from penman.types import (
Target,
BasicTriple,
)
from penman.tree import Tree
from penman._lexer import (
PENMAN_RE,
TRIPLE_RE,
lex,
TokenIterator,
lex,
)
from penman.tree import Tree
from penman.types import (
BasicTriple,
Target,
)


logger = logging.getLogger('penman')

Expand Down
25 changes: 12 additions & 13 deletions penman/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
"""
Serialization of PENMAN graphs.
"""
from typing import Optional, Union, Iterable, Iterator, List, IO
from pathlib import Path
from typing import IO, Iterable, Iterator, List, Optional, Union

from penman.types import (
Variable,
BasicTriple,
from penman import layout
from penman._format import (
format,
format_triples,
)
from penman.tree import Tree
from penman.graph import Graph
from penman.model import Model
from penman._parse import (
parse,
iterparse,
parse,
parse_triples,
)
from penman._format import (
format,
format_triples,
from penman.graph import Graph
from penman.model import Model
from penman.tree import Tree
from penman.types import (
BasicTriple,
Variable,
)
from penman import layout


# "Utility" types; not Penman-specific

Expand Down
7 changes: 3 additions & 4 deletions penman/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
Functions for working with constant values.
"""

from typing import Union
from enum import Enum
import json
from enum import Enum
from typing import Union

from penman.types import Constant
from penman.exceptions import ConstantError

from penman.types import Constant

pytype = type # store because type() is redefined below

Expand Down
11 changes: 5 additions & 6 deletions penman/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
Data structures for Penman graphs and triples.
"""

from typing import (Union, Optional, Mapping, List, Dict, Set, NamedTuple)
from collections import defaultdict
import copy
from collections import defaultdict
from typing import Dict, List, Mapping, NamedTuple, Optional, Set, Union

from penman.epigraph import Epidata
from penman.exceptions import GraphError
from penman.types import (
Variable,
BasicTriple,
Constant,
Role,
Target,
BasicTriple,
Triples,
Variable,
)
from penman.epigraph import Epidata


CONCEPT_ROLE = ':instance'

Expand Down
10 changes: 6 additions & 4 deletions penman/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

from penman.codec import ( # noqa: F401
_decode as decode,
_iterdecode as iterdecode,
_dump as dump,
_dumps as dumps,
_encode as encode,
_iterdecode as iterdecode,
_load as load,
_loads as loads,
_dump as dump,
_dumps as dumps,
)

warnings.warn(
'The penman.interface module is deprecated. Use the functions from '
'the penman module directly, e.g., penman.decode().',
DeprecationWarning)
DeprecationWarning,
stacklevel=2,
)
13 changes: 6 additions & 7 deletions penman/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@
('b', ':ARG0', 'd')] : POP
"""

from typing import Union, Mapping, Callable, Any, List, Set, cast, Optional
import copy
import logging
from typing import Any, Callable, List, Mapping, Optional, Set, Union, cast

from penman.exceptions import LayoutError
from penman.types import (Variable, Role, BasicTriple, Branch, Node)
from penman.epigraph import Epidatum
from penman.surface import (Alignment, RoleAlignment)
from penman.tree import (Tree, is_atomic)
from penman.graph import (Graph, CONCEPT_ROLE)
from penman.exceptions import LayoutError
from penman.graph import CONCEPT_ROLE, Graph
from penman.model import Model

from penman.surface import Alignment, RoleAlignment
from penman.tree import Tree, is_atomic
from penman.types import BasicTriple, Branch, Node, Role, Variable

logger = logging.getLogger(__name__)

Expand Down
14 changes: 3 additions & 11 deletions penman/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@
Semantic models for interpreting graphs.
"""

from typing import (
cast, Optional, Tuple, List, Dict, Set, Iterable, Mapping, Any)
import random
import re
from collections import defaultdict
import random
from typing import Any, Dict, Iterable, List, Mapping, Optional, Set, Tuple, cast

from penman.exceptions import ModelError
from penman.types import (
Variable,
Role,
Constant,
Target,
BasicTriple
)
from penman.graph import CONCEPT_ROLE, Graph

from penman.types import BasicTriple, Constant, Role, Target, Variable

_ReificationSpec = Tuple[Role, Constant, Role, Role]
_Reified = Tuple[Constant, Role, Role]
Expand Down
1 change: 0 additions & 1 deletion penman/models/amr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from penman.model import Model


#: The roles are the edge labels of reifications. The purpose of roles
#: in a :class:`~penman.model.Model` is mainly to define the set of
#: valid roles, but they map to arbitrary data which is not used by
Expand Down
2 changes: 1 addition & 1 deletion penman/models/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
No-op semantic model definition.
"""

from penman.types import BasicTriple
from penman.model import Model
from penman.types import BasicTriple


class NoOpModel(Model):
Expand Down
7 changes: 3 additions & 4 deletions penman/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
Surface strings, tokens, and alignments.
"""

from typing import TypeVar, Type, Mapping, Tuple, Optional
from typing import Mapping, Optional, Tuple, Type, TypeVar

from penman.types import BasicTriple
from penman.graph import Graph
from penman.epigraph import Epidatum
from penman.exceptions import SurfaceError

from penman.graph import Graph
from penman.types import BasicTriple

T = TypeVar('T', bound='AlignmentMarker') # for classmethods

Expand Down
21 changes: 10 additions & 11 deletions penman/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
Tree and graph transformations.
"""

from typing import Optional, Dict, Set, List, Tuple
import logging
from typing import Dict, List, Optional, Set, Tuple

from penman.types import (Variable, Target, BasicTriple, Node)
from penman.epigraph import Epidata, Epidatum
from penman.exceptions import ModelError
from penman.epigraph import (Epidatum, Epidata)
from penman.surface import (Alignment, RoleAlignment, alignments)
from penman.tree import (Tree, is_atomic)
from penman.graph import (Graph, CONCEPT_ROLE)
from penman.model import Model
from penman.graph import CONCEPT_ROLE, Graph
from penman.layout import (
Push,
Pop,
POP,
Pop,
Push,
appears_inverted,
get_pushed_variable,
)

from penman.model import Model
from penman.surface import Alignment, RoleAlignment, alignments
from penman.tree import Tree, is_atomic
from penman.types import BasicTriple, Node, Target, Variable

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,7 +59,7 @@ def canonicalize_roles(t: Tree, model: Model) -> Tree:
def _canonicalize_node(node: Node, model: Model) -> Node:
var, edges = node
canonical_edges = []
for i, edge in enumerate(edges):
for edge in edges:
role, tgt = edge
# alignments aren't parsed off yet, so handle them superficially
role, tilde, alignment = role.partition('~')
Expand Down
Loading

0 comments on commit 1d2e8e0

Please sign in to comment.