Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ permissions:
contents: read

jobs:
static-code-analysis:
name: StaticCodingAnalysis (py${{ matrix.python-version}} ${{ matrix.toxenv-factors }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- python-version: '3.14' # latest
os: ubuntu-latest
- python-version: '3.9' # lowest
os: ubuntu-latest
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup Python Environment
# see https://github.com/actions/setup-python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Install project
run: pip install --user -e ".[testing]"
- name: Run Mypy
run: python -m mypy -v
build-and-test:
name: Test (${{ matrix.os }} py${{ matrix.python-version }} ${{ matrix.toxenv-factors }})
runs-on: ${{ matrix.os }}
Expand Down
34 changes: 34 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[mypy]

files = src/

show_error_codes = True
pretty = True

warn_unreachable = True
allow_redefinition = False

# ignore_missing_imports = False
# follow_imports = normal
# follow_imports_for_stubs = True

### Strict mode ###
warn_unused_configs = True
disallow_subclassing_any = True
disallow_any_generics = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
no_implicit_reexport = True

[mypy-pytest.*]
ignore_missing_imports = True

[mypy-tests.*]
disallow_untyped_decorators = False
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.

<!-- unreleased things below this line -->

* Added
* Assert static typing (via [#16])

[#16]: https://github.com/jkowalleck/rfc3987-syntax2/pull/16

## v1.1.1 - 2026-07-14

### Fork release `rfc3987-syntax2`
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ classifiers = [
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
"Topic :: Utilities"
"Topic :: Utilities",
"Typing :: Typed",
]
dependencies = ["lark>=1.2.2"]

Expand All @@ -41,6 +42,7 @@ Source = "https://github.com/jkowalleck/rfc3987-syntax2"

[project.optional-dependencies]
testing = [
"mypy>=1.15,<2",
"typing_extensions>=4.16.0",
"pytest>=8.3.5",
]
Expand Down
1 change: 1 addition & 0 deletions src/rfc3987_syntax2/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# see https://peps.python.org/pep-0561/
8 changes: 5 additions & 3 deletions src/rfc3987_syntax2/syntax_helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Callable

from lark import Lark, ParseTree, exceptions

from pathlib import Path
Expand Down Expand Up @@ -54,18 +56,18 @@ def parse(term: str, value: str) -> ParseTree:
return syntax_parser.parse(value, start=term)


def is_valid_syntax(term: str, value: str):
def is_valid_syntax(term: str, value: str) -> bool:
try:
parse(term=term, value=value)
return True
except exceptions.LarkError:
return False


def make_syntax_validator(rule_name):
def make_syntax_validator(rule_name: str) -> Callable[[str], bool]:
parser = Lark(grammar, start=rule_name, parser=RFC3987_SYNTAX_PARSER_TYPE)

def syntax_validator(text):
def syntax_validator(text: str) -> bool:
try:
parser.parse(text)
return True
Expand Down
2 changes: 1 addition & 1 deletion src/rfc3987_syntax2/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path


def load_grammar(path: Path):
def load_grammar(path: Path) -> str:
with open(path, "r", encoding="utf-8") as file:
return file.read()
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SyntaxCase(TypedDict):

def valid_syntax_data() -> T_syntax_file:
with open(TESTS_DATA_FILES['valid_syntax'], "r", encoding="utf-8") as f:
return json.load(f)
return json.load(f) # type:ignore[no-any-return]

def invalid_syntax_data() -> T_syntax_file:
with open(TESTS_DATA_FILES['invalid_syntax'], "r", encoding="utf-8") as f:
return json.load(f)
return json.load(f) # type:ignore[no-any-return]
4 changes: 2 additions & 2 deletions tests/test_syntax.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import TYPE_CHECKING

import pytest
from typing import Callable
from typing import Any, Callable

import rfc3987_syntax2 as sut

from . import valid_syntax_data, invalid_syntax_data, SyntaxCase, T_syntax_file


def syntax_data_as_params(src_cb: Callable[[], T_syntax_file]):
def syntax_data_as_params(src_cb: Callable[[], T_syntax_file]) -> Any:
for term, examples in src_cb().items():
for example in examples:
yield pytest.param(term, example, id=f"{term}-{example['value']}")
Expand Down