Repository navigation
Tighten linting: every ruff rule, basedpyright in all mode failing on warnings, strict pytest - #16
Merged
Merged
Conversation
Turns on reportUnnecessaryIsInstance, reportUnnecessaryComparison, reportUnnecessaryContains, reportUnreachable, reportUnnecessaryCast, reportUnusedFunction and reportDeprecated. Module-name lookups in ConfigState compare against the enum's value, so the checker no longer narrows the module to None and calls the hub-step and conditional-backhaul code unreachable. Dead checks and casts are removed; guards against caller input outside the declared types are kept with a targeted ignore.
Annotate each instance and class attribute the rule reports: pydantic model_config as ClassVar[ConfigDict] (the convention core/base.py already follows), __slots__ as ClassVar[tuple[str, ...]], resolver identity_type with the resolver's own identity type, and instance attributes where __init__ assigns them. Two test lines that exist to provoke a checker error or build a pydantic validator keep their form and ignore the rule.
…e reportUnknown rules still off
…d; check the examples' types; strict pytest
…import-order and docstring-format rules
Imports used only in annotations move under TYPE_CHECKING, except where pydantic reads them: the model base classes are listed in runtime-evaluated-base-classes. Local imports move to the top, except those that break an import cycle or load an optional extra, which keep a noqa with the reason.
…arked to split when it next changes
…es that alone pass 88 columns
…15 slowest pytest-xdist with -n logical and --dist worksteal: the suite takes 12 s in place of 50 s on 12 vCPUs. A selection that takes in a live test runs in one process, since each worker would connect its own client with its own rate limit, and the tests that write would write to the one enterprise at once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Linting, type checking and the test run are tightened, and each now fails on anything it reports.
allmode overpyveloand the examples, and any warning fails the check (failOnWarnings = true). Onmain, the extra rules of therecommendedmode only warned, so CI passed with them reported. An example is the unannotatedself._hubsinhub_steps.py.ALL. Each rule that is off is listed inpyproject.tomlwith its reason.--strict-markers,--strict-config,xfail_strictandfilterwarnings = ["error"].-n logical), with--dist workstealand--durations=15. The suite takes 12 s instead of 50 s on 12 vCPUs.Each tool works as a ratchet. A rule the code doesn't yet meet goes in an "Off until the code meets them" list. To turn one on, delete its line and fix what it reports. The ruff list is now empty. The basedpyright list still has the rules named under follow-ups.
What is off for good
COM812,ISC001CPY001LICENSEANN401, basedpyrightreportAny,reportExplicitAnyAnyis how the wire types are writtenSLF001reportPrivateUsagechecks it, with its own ignoresTRY003,EM101,EM102RUF036X | None | MISSING, with the unset sentinel lastreportImplicitStringConcatenationTests also skip asserts (
S101), docstrings (D1) and magic values (PLR2004), plus a few security rules that don't apply to test data; each has a comment. The wire classes underclient/schemas,client/modelsandclient/enumsneed a module docstring, but no class or method docstrings.What changed in the code
D205wants a one-line summary followed by a blank line, each was reworded into a short summary plus a body that holds the rest. No facts were dropped, though some of the new bodies are thin.# noqa: E501 (a test's name).Usage:docstrings are split with\continuations, and those six docstrings are now raw strings.C901and thePLR09xxlimits) are on. The 128 existing functions over a limit carry anoqamarked(existing: split it when it next changes). 88 of them are over the limit on arguments (PLR0913).TCkeeps a model's field imports at runtime throughruntime-evaluated-base-classes. The newtests/test_models_build.pyrebuilds every pydantic model, with each generic model built for each of its type parameters (1021 cases). An import moved underTYPE_CHECKINGthat a model needs therefore fails a test.reportUnreachableshowed that_hub_stepsandconditional_backhaulinconfig/state.pycompared aLiteralwith aStrEnum. basedpyright then treated most of both functions as unreachable. They now compare with.value.# pyright: ignores are removed. The 46 that name areportUnknown*rule are kept for when those rules go on.Parallel tests
-n logicaland notauto. With psutil installed,autocounts physical cores, which is 6 here, and the suite then takes 18 s. Without psutil, both give the vCPU count. CI's runners have 4 vCPUs.workstealand not the defaultload. The default splits the tests among workers up front, and the workers that finish early then sit idle. Withloadthe suite took 22 s.pytest_xdist_auto_num_workershook intests/conftest.pyevaluates-m. If it selects a read-only or a writing live test, the hook returns no workers. Otherwise each worker would connect its own client, each with its own rate limit, so together they could exceed the VCO's limit many times over, and thelive_writetests would write to the one enterprise at once. An explicit-n 3still gets its 3 workers. The hook imports pytest'sExpressionfrom_pytest.mark.expression, so it may need a change on a pytest upgrade.-n0for that.--pdbgoes back to one process by itself. The README says this.Public API changes
There are no users yet, so these changes come without shims:
redo_patch(*, include_clashes),not_redone,confirm_save(message, *, auto_yes, plan),repaired_entry(..., *, conditional_backhaul)andhub_in_use_message(..., *, refuse).type→type_in the firewall metrics methods.GroupByProxy.agg'ssum/min/max→sum_/min_/max_.make_jsonrpc_response'sid→id_.ResultType/ItemType→result_type/item_type.PaginatedVcoModelgainsmax_pages(a property with a setter),page_has_more,page_next_linkandrecord_page_cursor().MetricFrame._from_polarsis nowfrom_polars.asserts become explicit raises:TypeErrorfor a wrong module type,ValueErrorfor a bad argument, andAssertionErrorfor an internal invariant.run_diagnostic(max_retries=-1)now raisesValueError.zip(..., strict=True)everywhere. Incore/merge.py's_check_fixed_value, unequal lengths now raise where they were silently truncated before.Worth a look
core/merge.py_check_fixed_value: confirm that the lengths are always meant to be equal there.core/show.py:RUF071wantedos.path.commonprefixreplaced bycommonpath. The code wants a character prefix, so it keepscommonprefixwith anoqa.D205off for good and restore the original long summaries, wrapped.Testing
scripts/check.shpasses:ruff checkandruff format --checkare clean.mainhad 6839 passed; the difference is the 1021 new model-build cases. The parallel suite passed on four runs in a row.-mselection, the worker count is as described above: 12 for the default, and one process forintegration,integration and not live_write,live_writeand an empty-m.Follow-ups
reportUnknownVariableType,reportUnknownArgumentType,reportUnknownMemberTypeandreportUnknownLambdaType(about 540 warnings), andreportUnusedCallResult(153).reportUnnecessaryTypeIgnoreComment. While areportUnknown*rule is off, every ignore that names it counts as unnecessary.