Skip to content

Configure pyrefly and ruff, and fix the types rather than suppress the diagnostics - #89

Open
hhoppe wants to merge 15 commits into
google:mainfrom
hhoppe:pyrefly-ruff
Open

hhoppe wants to merge 15 commits into
google:mainfrom
hhoppe:pyrefly-ruff

Conversation

@hhoppe

@hhoppe hhoppe commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

This configures pyrefly and ruff in pyproject.toml and cleans up the code so that all five linters (pyrefly, ruff, mypy strict, pylint, pyink) run clean, while keeping mypy and pylint happy at the same time.

Rather than adding a suppression per diagnostic, it fixes the underlying types:

  • pyrefly: ignore pragmas drop from 11 to 0 in mediapy/__init__.py and from 30 to 2 in mediapy_test.py (the two that remain concern matplotlib.cm stubs).
  • With current tool versions, main itself does not lint clean: mypy strict reports 3 errors, pylint reports E1101 on finfo.eps, and pyink would reformat both files. This branch is clean.

Other changes:

  • Remove pytype, which is no longer maintained, from the dev dependencies and the config.
  • Drop the ~/.cache/mypy cache_dir setting, which was a personal preference.
  • Pin pyink's target-version to py310; otherwise it infers all of py310..py315 and warns.
  • Rewrite the Mandelbrot example, which pyrefly flagged for reading a possibly uninitialized loop variable; the new version computes a fractional escape time.

No change in library functionality. All 209 tests pass under Python 3.10 (numpy 2.2.6) and 3.14.

This supersedes #86, which combined these changes with unrelated ones. It overlaps with the suppressions added in 849e6f4; cc @h-joo, since this is the fix-the-types alternative to that commit. I'm happy to adapt the audio-track support once it lands, if its new code needs the same treatment.

🤖 Generated with Claude Code

@hhoppe

hhoppe commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Unit tests pass on the fork's CI for head commit 25dd25d (Python 3.10 and 3.x): https://github.com/hhoppe/mediapy/actions/runs/36083142417

…agnostics

- Annotate list_audios and index the audios mapping through a cast, as
  show_videos already does for videos, removing the pyrefly pragma and three
  mypy strict errors.
- Return Generator from _audio_via_local_file, like its sibling context
  managers, to avoid the deprecated contextmanager overload.
- Use capture_html_string in the two new audio tests, removing three pyrefly
  pragmas.
@hhoppe

hhoppe commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

After merging main (with the new audio-track support) and fixing the types in that code, unit tests pass on the fork's CI for head commit 1314346 (Python 3.10 and 3.x): https://github.com/hhoppe/mediapy/actions/runs/36648013416

…me starting with a lowercase letter, and rename the one constant it now flags

The unparenthesized alternation parsed as '^[a-z][a-z0-9]?' or
'[A-Z]([A-Z_]*[A-Z])?$', and pylint matches from the start of the name, so the
first branch accepted every lowercase-initial name, silently disabling
invalid-name.  With the anchors applied to both branches, pylint flags only the
module-level constant new_file in mediapy_examples, renamed to NEW_FILE.
@hhoppe

hhoppe commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Added a fix for a precedence bug in good-names-rgxs: the unparenthesized alternation accepted any name starting with a lowercase letter, silently disabling invalid-name. With the fix, pylint flags only one module-level constant in mediapy_examples.py, now renamed. Unit tests pass on the fork's CI for head commit 3da28cc (Python 3.10 and 3.x): https://github.com/hhoppe/mediapy/actions/runs/37025968975

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant