Skip to content

Commit

Permalink
style: disable global ignore for E402 in ruff (#2572)
Browse files Browse the repository at this point in the history
Disabled the global ignore for E402 in ruff and fixed it where possible.
Where it couldn't be fixed easily, replaced it with file level ignores.
  • Loading branch information
aucampia authored Sep 4, 2023
1 parent 0eb86ab commit a9fcf34
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 116 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ ignore = [
# https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated
"E203", # whitespace before ':'
"E231", # missing whitespace after ','
"E402", # Module level import not at top of file
]

# Same as Black.
Expand Down Expand Up @@ -130,6 +129,10 @@ line-length = 88
"N815", # Variable in class scope should not be mixedCase
"N999", # Invalid module name
]
"{test/conftest.py,rdflib/namespace/__init__.py,rdflib/__init__.py,rdflib/plugins/sparql/__init__.py}" = [
"E402", # Module level import not at top of file
]


[tool.black]
required-version = "23.7.0"
Expand Down
13 changes: 7 additions & 6 deletions rdflib/extras/external_graph_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# encoding: utf-8
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Any, Dict, List

if TYPE_CHECKING:
from rdflib.graph import Graph


"""Convert (to and) from rdflib graphs to other well known graph libraries.
Currently the following libraries are supported:
Expand All @@ -13,12 +20,6 @@
see ../../test/test_extras_external_graph_libs.py for conditional tests
"""

import logging
from typing import TYPE_CHECKING, Any, Dict, List

if TYPE_CHECKING:
from rdflib.graph import Graph

logger = logging.getLogger(__name__)


Expand Down
11 changes: 6 additions & 5 deletions rdflib/plugins/serializers/nt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from __future__ import annotations

"""
N-Triples RDF graph serializer for RDFLib.
See <http://www.w3.org/TR/rdf-testcases/#ntriples> for details about the
format.
"""
import codecs
import warnings
from typing import IO, TYPE_CHECKING, Optional, Tuple, Union
Expand All @@ -16,6 +11,12 @@
if TYPE_CHECKING:
from rdflib.graph import _TripleType

"""
N-Triples RDF graph serializer for RDFLib.
See <http://www.w3.org/TR/rdf-testcases/#ntriples> for details about the
format.
"""

__all__ = ["NTSerializer"]


Expand Down
14 changes: 7 additions & 7 deletions rdflib/plugins/sparql/algebra.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
from __future__ import annotations

"""
Converting the 'parse-tree' output of pyparsing to a SPARQL Algebra expression
http://www.w3.org/TR/sparql11-query/#sparqlQuery
"""

import collections
import functools
import operator
Expand Down Expand Up @@ -45,6 +38,13 @@
# Some convenience methods
from rdflib.term import BNode, Identifier, Literal, URIRef, Variable

"""
Converting the 'parse-tree' output of pyparsing to a SPARQL Algebra expression
http://www.w3.org/TR/sparql11-query/#sparqlQuery
"""


def OrderBy(p: CompValue, expr: List[CompValue]) -> CompValue:
return CompValue("OrderBy", p=p, expr=expr)
Expand Down
9 changes: 5 additions & 4 deletions rdflib/plugins/sparql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

from typing import TYPE_CHECKING, Dict, List, Optional, Set

"""
Utility functions for supporting the XML Schema Datatypes hierarchy
"""

from rdflib.namespace import XSD

if TYPE_CHECKING:
from rdflib.term import URIRef


"""
Utility functions for supporting the XML Schema Datatypes hierarchy
"""

XSD_DTs: Set[URIRef] = set(
(
XSD.integer,
Expand Down
33 changes: 17 additions & 16 deletions rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
from __future__ import annotations

"""
These method recursively evaluate the SPARQL Algebra
evalQuery is the entry-point, it will setup context and
return the SPARQLResult object
evalPart is called on each level and will delegate to the right method
A rdflib.plugins.sparql.sparql.QueryContext is passed along, keeping
information needed for evaluation
A list of dicts (solution mappings) is returned, apart from GroupBy which may
also return a dict of list of dicts
"""

import collections
import itertools
import json as j
Expand Down Expand Up @@ -63,6 +47,23 @@
if TYPE_CHECKING:
from rdflib.paths import Path


"""
These method recursively evaluate the SPARQL Algebra
evalQuery is the entry-point, it will setup context and
return the SPARQLResult object
evalPart is called on each level and will delegate to the right method
A rdflib.plugins.sparql.sparql.QueryContext is passed along, keeping
information needed for evaluation
A list of dicts (solution mappings) is returned, apart from GroupBy which may
also return a dict of list of dicts
"""

_Triple = Tuple[Identifier, Identifier, Identifier]


Expand Down
16 changes: 8 additions & 8 deletions rdflib/plugins/sparql/operators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
from __future__ import annotations

"""
This contains evaluation functions for expressions
They get bound as instances-methods to the CompValue objects from parserutils
using setEvalFn
"""

import datetime as py_datetime # naming conflict with function within this module
import hashlib
import math
Expand Down Expand Up @@ -48,6 +40,14 @@
Variable,
)

"""
This contains evaluation functions for expressions
They get bound as instances-methods to the CompValue objects from parserutils
using setEvalFn
"""


def Builtin_IRI(expr: Expr, ctx: FrozenBindings) -> URIRef:
"""
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/parserutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@ def _prettify_sub_parsetree(


# hurrah for circular imports
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError
from rdflib.plugins.sparql.sparql import NotBoundError, SPARQLError # noqa: E402
16 changes: 8 additions & 8 deletions rdflib/plugins/sparql/results/csvresults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from __future__ import annotations

import codecs
import csv
from typing import IO, Dict, List, Optional, Union

from rdflib.plugins.sparql.processor import SPARQLResult
from rdflib.query import Result, ResultParser, ResultSerializer
from rdflib.term import BNode, Identifier, Literal, URIRef, Variable

"""
This module implements a parser and serializer for the CSV SPARQL result
Expand All @@ -9,14 +17,6 @@
"""

import codecs
import csv
from typing import IO, Dict, List, Optional, Union

from rdflib.plugins.sparql.processor import SPARQLResult
from rdflib.query import Result, ResultParser, ResultSerializer
from rdflib.term import BNode, Identifier, Literal, URIRef, Variable


class CSVResultParser(ResultParser):
def __init__(self):
Expand Down
15 changes: 8 additions & 7 deletions rdflib/serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from __future__ import annotations

from typing import IO, TYPE_CHECKING, Any, Optional, TypeVar, Union

from rdflib.term import URIRef

if TYPE_CHECKING:
from rdflib.graph import Graph


"""
Serializer plugin interface.
Expand All @@ -12,13 +20,6 @@
"""

from typing import IO, TYPE_CHECKING, Any, Optional, TypeVar, Union

from rdflib.term import URIRef

if TYPE_CHECKING:
from rdflib.graph import Graph

__all__ = ["Serializer"]

_StrT = TypeVar("_StrT", bound=str)
Expand Down
20 changes: 9 additions & 11 deletions rdflib/tools/defined_namespace_creator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from __future__ import annotations

import argparse
import datetime
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, List, Tuple

from rdflib.graph import Graph
from rdflib.namespace import DCTERMS, OWL, RDFS, SKOS
from rdflib.util import guess_format

"""
This rdflib Python script creates a DefinedNamespace Python file from a given RDF file
Expand All @@ -12,17 +21,6 @@
Nicholas J. Car, Dec, 2021
"""
import argparse
import datetime
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, List, Tuple

sys.path.append(str(Path(__file__).parent.absolute().parent.parent))

from rdflib.graph import Graph
from rdflib.namespace import DCTERMS, OWL, RDFS, SKOS
from rdflib.util import guess_format

if TYPE_CHECKING:
from rdflib.query import ResultRow
Expand Down
45 changes: 23 additions & 22 deletions rdflib/util.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
from __future__ import annotations

"""
Some utility functions.
Miscellaneous utilities
* list2set
* first
* uniq
* more_than
Term characterisation and generation
* to_term
* from_n3
Date/time utilities
* date_time
* parse_date_time
"""

from calendar import timegm
from os.path import splitext

Expand Down Expand Up @@ -53,6 +31,29 @@
if TYPE_CHECKING:
from rdflib.graph import Graph


"""
Some utility functions.
Miscellaneous utilities
* list2set
* first
* uniq
* more_than
Term characterisation and generation
* to_term
* from_n3
Date/time utilities
* date_time
* parse_date_time
"""

__all__ = [
"list2set",
"first",
Expand Down
5 changes: 1 addition & 4 deletions test/plugins/parser/example/rdflib/plugin/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import TYPE_CHECKING, Set, Tuple

from rdflib.namespace import Namespace
from rdflib.parser import Parser

if TYPE_CHECKING:
from rdflib.graph import Graph
from rdflib.namespace import Namespace
from rdflib.parser import InputSource
from rdflib.term import URIRef

Expand All @@ -26,6 +26,3 @@ def constant_output(
cls,
) -> Set[Tuple["URIRef", "URIRef", "URIRef"]]:
return {(cls.namespace().subj, cls.namespace().pred, cls.namespace().obj)}


from rdflib.namespace import Namespace # noqa: F811
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from typing import Any

from rdflib import Namespace
from rdflib.plugins.sparql.evaluate import evalPart
from rdflib.plugins.sparql.evalutils import _eval
from rdflib.plugins.sparql.sparql import SPARQLError


def custom_eval_extended(ctx: Any, extend: Any) -> Any:
for c in evalPart(ctx, extend.p):
Expand All @@ -24,11 +29,6 @@ def custom_eval(ctx: Any, part: Any) -> Any:
raise NotImplementedError()


from rdflib import Namespace
from rdflib.plugins.sparql.evaluate import evalPart
from rdflib.plugins.sparql.evalutils import _eval
from rdflib.plugins.sparql.sparql import SPARQLError

namespace = Namespace("example:rdflib:plugin:sparqleval:")
function_uri = namespace["function"]
function_result = namespace["result"]
Loading

0 comments on commit a9fcf34

Please sign in to comment.