Skip to content
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: type checks

on:
push:
branches:
- main
- 8.x
pull_request:

jobs:

pyright:
name: Check Typing
runs-on: ubuntu-latest
env:
MESSAGE: |
Your code contains type errors.
Please set up your development environment and run the type checking command.
https://icalendar.readthedocs.io/en/stable/contribute/development.html#check-typing
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Install uv and Python
uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
enable-cache: false
version: "0.13.4"
- name: Install dependencies
run: make .venv
- name: Check icalendar
run: |
if ! make test-types; then
echo "$MESSAGE"
exit 1
fi
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SHELL = bash

# You can set these variables from the command line.
SPHINXOPTS ?=
PYRIGHTOPTS ?=
PAPER ?=
VERSION ?=

Expand Down Expand Up @@ -152,6 +153,10 @@ test: .venv ## Run code tests and coverage
.PHONY: test-dist
test-dist: ## Build and test the distribution files
@src/icalendar/tests/test_create_release.sh

.PHONY: test-types
test-types: .venv
@uv run pyright $(PYRIGHTOPTS)
# /test


Expand Down
17 changes: 17 additions & 0 deletions docs/contribute/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ The following command shows how to run tests in Python 3.14.

tox's `CLI interface documentation <https://tox.wiki/en/stable/reference/cli.html>`_.

Check Typing
------------

:term:`pyright` flags up typing issues in the Python files.

Use the following command to check for typing issues during development.

.. code-block:: shell

make test-types

:term:`pyright` is widely used and we recommend using a plugin for the code editor to highlight typing issues during development.

.. seealso::

:file:`pyproject.toml` contains the :term:`pyright` configuration.
`pyright documentation <https://github.com/microsoft/pyright/blob/main/docs/README.md>`_

Format code
-----------
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Glossary
.. seealso::

:rfc:`5545#section-3.6`

pyright
`pyright <https://github.com/microsoft/pyright>`_ is a command line tool for type checking of Python files.
1 change: 1 addition & 0 deletions news/2007.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :term:`pyright` type checking to CI, documentation, :file:`Makefile` and :file:`pyproject.toml`. @niccokunzmann
72 changes: 72 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ dev = [
{include-group = "test"},
{include-group = "docs"},
{include-group = "formatting"},
"pyright>=1.1.414",
"towncrier>=25.8.0",
"tox",
"tox-uv",
Expand Down Expand Up @@ -254,6 +255,9 @@ extend-safe-fixes = [
"src/icalendar/tests/rfc_6321_xcal/**" = [
"S314", # unsafe XML parsing
]
"src/icalendar/tests/typing/**" = [
"F841", # unused variable - we need them for type checks
]

"src/icalendar/cal/**" = [
"A002", # argument shadowing builtin (sorted)
Expand Down Expand Up @@ -381,3 +385,71 @@ icalendar = { workspace = true, editable = true }
members = [
".",
]

[tool.pyright]
# See https://github.com/microsoft/pyright/blob/main/docs/configuration.md
strict = [
"src/icalendar/tests/typing/"
]

exclude = [
"**/__pycache__",
]

ignore = [
# Test files can be ignored
"src/icalendar/tests/**/test_*",
"src/icalendar/tests/conftest.py",
# These files already have typing issues.
"src/icalendar/alarms.py",
"src/icalendar/attr.py",
"src/icalendar/cal/alarm.py",
"src/icalendar/cal/availability.py",
"src/icalendar/cal/available.py",
"src/icalendar/cal/calendar.py",
"src/icalendar/cal/component_factory.py",
"src/icalendar/cal/component.py",
"src/icalendar/cal/event.py",
"src/icalendar/cal/free_busy.py",
"src/icalendar/cal/journal.py",
"src/icalendar/cal/lazy.py",
"src/icalendar/cal/timezone.py",
"src/icalendar/cal/todo.py",
"src/icalendar/caselessdict.py",
"src/icalendar/fuzzing/ical_fuzzer.py",
"src/icalendar/param.py",
"src/icalendar/parser/content_line.py",
"src/icalendar/parser/ical/component.py",
"src/icalendar/parser/ical/lazy.py",
"src/icalendar/parser/parameter.py",
"src/icalendar/parser_tools.py",
"src/icalendar/parser/xcal/property.py",
"src/icalendar/prop/binary.py",
"src/icalendar/prop/broken.py",
"src/icalendar/prop/categories.py",
"src/icalendar/prop/conference.py",
"src/icalendar/prop/dt/base.py",
"src/icalendar/prop/dt/datetime.py",
"src/icalendar/prop/dt/list.py",
"src/icalendar/prop/dt/period.py",
"src/icalendar/prop/dt/time.py",
"src/icalendar/prop/dt/types.py",
"src/icalendar/prop/empty.py",
"src/icalendar/prop/factory.py",
"src/icalendar/prop/float.py",
"src/icalendar/prop/image.py",
"src/icalendar/prop/recur/skip.py",
"src/icalendar/prop/text.py",
"src/icalendar/prop/uid.py",
"src/icalendar/prop/unknown.py",
"src/icalendar/prop/uri.py",
"src/icalendar/prop/xml_reference.py",
"src/icalendar/timezone/equivalent_timezone_ids.py",
"src/icalendar/timezone/__init__.py",
"src/icalendar/timezone/pytz.py",
"src/icalendar/timezone/tzid.py",
"src/icalendar/timezone/tzp.py",
"src/icalendar/timezone/zoneinfo.py",
]

reportMissingImports = "error"
18 changes: 18 additions & 0 deletions src/icalendar/tests/typing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Typing tests.

Run these tests with

make test-types

Valid types in this directory are enforced.
"""


def test_wrong_type():
"""If this test is commented in, you can see an error.

error: Type "Literal[1]" is not assignable to declared type "str"
"Literal[1]" is not assignable to "str" (reportAssignmentType)
"""
# a = 1
# sequence: str = a # pyright: ignore[reportUnusedVariable]
Loading