forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from astral-sh:main #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
## Summary Format conflicting declared types as ``` `str`, `int` and `bytes` ``` Thanks to @AlexWaygood for the initial draft. @dcreager, looking forward to your one-character follow-up PR.
## Summary Adds a new micro-benchmark as a regression test for astral-sh/ty#627. ## Test Plan Ran the benchmark on the parent commit of 89d915a, and verified that it took > 1s, while it takes ~10 ms after the fix.
…#18938) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This converts the MRE in #670 into a fixture test for `annotate-snippets`.
It turns out that `annotate-snippets` doesn't do a great job of consistently handling tabs. The intent of the implementation is clearly to expand tabs into 4 ASCII whitespace characters. But there are a few places where the column computation wasn't taking this expansion into account. In particular, the `unicode-width` crate returns `None` for a `\t` input, and `annotate-snippets` would in turn treat this as either zero columns or one column. Both are wrong. In patching this, it caused one of the existing `annotate-snippets` tests to fail. I spent a fair bit of time on it trying to fix it before coming to the conclusion that the test itself was wrong. In particular, the annotation ranges are 4 bytes off. However, when the range was wrong, the buggy code was rendering the example as intended since `\t` characters were treated as taking up zero columns of space. Now that they are correctly computed as taking up 4 columns of space, the offsets of the test needed to be adjusted. Fixes #670
…8960) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…rendering (#18965) It turns out that astral-sh/ty#18692 also fixed astral-sh/ty#203. This PR adds a regression test for it. (Locally, I "unfixed" the bug and confirmed that this is actually a regression test.) Fixes astral-sh/ty#203
## Summary Part of #15584 This PR adds a fix safety section to [fast-api-non-annotated-dependency (FAST002)](https://docs.astral.sh/ruff/rules/fast-api-non-annotated-dependency/#fast-api-non-annotated-dependency-fast002). It also re-words the availability section since I found it confusing. The lint/fix was added in #11579 as always unsafe. No reasoning is given in the original PR/code as to why this was chosen. Example of why the fix is unsafe: https://play.ruff.rs/3bd0566e-1ef6-4cec-ae34-3b07cd308155 ```py from fastapi import Depends, FastAPI, Query app = FastAPI() # Fix will remove the parameter default value @app.get("/items/") async def read_items(commons: dict = Depends(common_parameters)): return commons # Fix will delete comment and change default parameter value @app.get("/items/") async def read_items_1(q: str = Query( # This comment will be deleted default="rick")): return q ``` After fixing both instances of `FAST002`: ```py from fastapi import Depends, FastAPI, Query from typing import Annotated app = FastAPI() # Fix will remove the parameter default value @app.get("/items/") async def read_items(commons: Annotated[dict, Depends(common_parameters)]): return commons # Fix will delete comment and change default parameter value @app.get("/items/") async def read_items_1(q: Annotated[str, Query()] = "rick"): return q ```
…lambda's body contains an assignment expression (#18678) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary This PR also supresses the fix if the assignment expression target shadows one of the lambda's parameters. Fixes #18675 <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan Add regression tests. <!-- How was it tested? -->
## Summary Setting `TY_MEMORY_REPORT=full` will generate and print a memory usage report to the CLI after a `ty check` run: ``` =======SALSA STRUCTS======= `Definition` metadata=7.24MB fields=17.38MB count=181062 `Expression` metadata=4.45MB fields=5.94MB count=92804 `member_lookup_with_policy_::interned_arguments` metadata=1.97MB fields=2.25MB count=35176 ... =======SALSA QUERIES======= `File -> ty_python_semantic::semantic_index::SemanticIndex` metadata=11.46MB fields=88.86MB count=1638 `Definition -> ty_python_semantic::types::infer::TypeInference` metadata=24.52MB fields=86.68MB count=146018 `File -> ruff_db::parsed::ParsedModule` metadata=0.12MB fields=69.06MB count=1642 ... =======SALSA SUMMARY======= TOTAL MEMORY USAGE: 577.61MB struct metadata = 29.00MB struct fields = 35.68MB memo metadata = 103.87MB memo fields = 409.06MB ``` Eventually, we should integrate these numbers into CI in some form. The one limitation currently is that heap allocations in salsa structs (e.g. interned values) are not tracked, but memoized values should have full coverage. We may also want a peak memory usage counter (that accounts for non-salsa memory), but that is relatively simple to profile manually (e.g. `time -v ty check`) and would require a compile-time option to avoid runtime overhead.
## Summary Add a benchmark for the problematic case in astral-sh/ty#711, which will potentially be solved in #18955
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Carl Meyer <carl@astral.sh>
Most of the work here was doing some light refactoring to facilitate sensible testing. That is, we don't want to list every builtin included in most tests, so we add some structure to the completion type returned. Tests can now filter based on whether a completion is a builtin or not. Otherwise, builtins are found using the existing infrastructure for `object.attr` completions (where we hard-code the module name `builtins`). I did consider changing the sort order based on whether a completion suggestion was a builtin or not. In particular, it seemed like it might be a good idea to sort builtins after other scope based completions, but before the dunder and sunder attributes. Namely, it seems likely that there is an inverse correlation between the size of a scope and the likelihood of an item in that scope being used at any given point. So it *might* be a good idea to prioritize the likelier candidates in the completions returned. Additionally, the number of items introduced by adding builtins is quite large. So I wondered whether mixing them in with everything else would become too noisy. However, it's not totally clear to me that this is the right thing to do. Right now, I feel like there is a very obvious lexicographic ordering that makes "finding" the right suggestion to activate potentially easier than if the ranking mechanism is less clear. (Technically, the dunder and sunder attributes are not sorted lexicographically, but I'd put forward that most folks don't have an intuitive understanding of where `_` ranks lexicographically with respect to "regular" letters. Moreover, since dunder and sunder attributes are all grouped together, I think the ordering here ends up being very obvious after even a quick glance.)
I renamed a field on a `Completion` struct in #18982, and it looks like this caused the playground to fail to build: https://github.com/astral-sh/ruff/actions/runs/15928550050/job/44931734349 Maybe building that playground can be added to CI for pull requests?
## Summary I think this should be the last step before combining `OldDiagnostic` and `ruff_db::Diagnostic`. We can't store a `NoqaCode` on `ruff_db::Diagnostic`, so I converted the `noqa_code` field to an `Option<String>` and then propagated this change to all of the callers. I tried to use `&str` everywhere it was possible, so I think the remaining `to_string` calls are necessary. I spent some time trying to convert _everything_ to `&str` but ran into lifetime issues, especially in the `FixTable`. Maybe we can take another look at that if it causes a performance regression, but hopefully these paths aren't too hot. We also avoid some `to_string` calls, so it might even out a bit too. ## Test Plan Existing tests --------- Co-authored-by: Micha Reiser <micha@reiser.io>
## Summary Under preview 🧪 I've expanded rule `PYI016` to also flag type union duplicates containing `None` and `Optional`. ## Test Plan Examples/tests have been added. I've made sure that the existing examples did not change unless preview is enabled. ## Relevant Issues * #18508 (discussing introducing/extending a rule to flag `Optional[None]`) * #18546 (where I discussed this addition with @AlexWaygood) --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
## Summary Ensure that we correctly infer calls such as `tuple((1, 2))`, `tuple(range(42))`, etc. Ensure that we emit errors on invalid calls such as `tuple[int, str]()`. ## Test Plan Mdtests
This PR updates our unpacking assignment logic to use the new tuple machinery. As a result, we can now unpack variable-length tuples correctly. As part of this, the `TupleSpec` classes have been renamed to `Tuple`, and can now contain any element (Rust) type, not just `Type<'db>`. The unpacker uses a tuple of `UnionBuilder`s to maintain the types that will be assigned to each target, as we iterate through potentially many union elements on the rhs. We also add a new consuming iterator for tuples, and update the `all_elements` methods to wrap the result in an enum (similar to `itertools::Position`) letting you know which part of the tuple each element appears in. I also added a new `UnionBuilder::try_build`, which lets you specify a different fallback type if the union contains no elements.
This PR extracts a lot of the complex logic in the `match_parameters` and `check_types` methods of our call binding machinery into separate helper types. This is setup for #18996, which will update this logic to handle variadic arguments. To do so, it is helpful to have the per-argument logic extracted into a method that we can call repeatedly for each _element_ of a variadic argument. This should be a pure refactoring, with no behavioral changes.
Re: #18979 (comment) Each check increases the runtime by a factor of 3, so this should be an order of magnitude faster.
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of #18972 This PR makes [timeout-error-alias (UP041)](https://docs.astral.sh/ruff/rules/timeout-error-alias/#timeout-error-alias-up041)'s example error out-of-the-box. [Old example](https://play.ruff.rs/87e20352-d80a-46ec-98a2-6f6ea700438b) ```py raise asyncio.TimeoutError ``` [New example](https://play.ruff.rs/d3b95557-46a2-4856-bd71-30d5f3f5ca44) ```py import asyncio raise asyncio.TimeoutError ``` ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
## Summary Part of #18972 This PR makes [invalid-envvar-value (PLE1507)](https://docs.astral.sh/ruff/rules/invalid-envvar-value/#invalid-envvar-value-ple1507)'s example error out-of-the-box. [Old example](https://play.ruff.rs/a46a9bca-edd5-4474-b20d-e6b6d87291ca) ```py os.getenv(1) ``` [New example](https://play.ruff.rs/8348d32d-71fa-422c-b228-e2bc343765b1) ```py import os os.getenv(1) ``` The "Use instead" section was also updated similarly. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of #18972 This PR makes [non-pep695-type-alias (UP040)](https://docs.astral.sh/ruff/rules/non-pep695-type-alias/#non-pep695-type-alias-up040)'s example error out-of-the-box. [Old example](https://play.ruff.rs/6beca1be-45cd-4e5a-aafa-6a0584c10d64) ```py ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` [New example](https://play.ruff.rs/bbad34da-bf07-44e6-9f34-53337e8f57d4) ```py from typing import Annotated, TypeAlias, TypeAliasType from annotated_types import Gt ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` Imports were also added to the "Use instead" section. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [ruff](https://docs.astral.sh/ruff) ([source](https://redirect.github.com/astral-sh/ruff), [changelog](https://redirect.github.com/astral-sh/ruff/blob/main/CHANGELOG.md)) | `==0.12.2` -> `==0.12.3` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>astral-sh/ruff (ruff)</summary> ### [`v0.12.3`](https://redirect.github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#0123) [Compare Source](https://redirect.github.com/astral-sh/ruff/compare/0.12.2...0.12.3) ##### Preview features - \[`flake8-bugbear`] Support non-context-manager calls in `B017` ([#​19063](https://redirect.github.com/astral-sh/ruff/pull/19063)) - \[`flake8-use-pathlib`] Add autofixes for `PTH100`, `PTH106`, `PTH107`, `PTH108`, `PTH110`, `PTH111`, `PTH112`, `PTH113`, `PTH114`, `PTH115`, `PTH117`, `PTH119`, `PTH120` ([#​19213](https://redirect.github.com/astral-sh/ruff/pull/19213)) - \[`flake8-use-pathlib`] Add autofixes for `PTH203`, `PTH204`, `PTH205` ([#​18922](https://redirect.github.com/astral-sh/ruff/pull/18922)) ##### Bug fixes - \[`flake8-return`] Fix false-positive for variables used inside nested functions in `RET504` ([#​18433](https://redirect.github.com/astral-sh/ruff/pull/18433)) - Treat form feed as valid whitespace before a line continuation ([#​19220](https://redirect.github.com/astral-sh/ruff/pull/19220)) - \[`flake8-type-checking`] Fix syntax error introduced by fix (`TC008`) ([#​19150](https://redirect.github.com/astral-sh/ruff/pull/19150)) - \[`pyupgrade`] Keyword arguments in `super` should suppress the `UP008` fix ([#​19131](https://redirect.github.com/astral-sh/ruff/pull/19131)) ##### Documentation - \[`flake8-pyi`] Make example error out-of-the-box (`PYI007`, `PYI008`) ([#​19103](https://redirect.github.com/astral-sh/ruff/pull/19103)) - \[`flake8-simplify`] Make example error out-of-the-box (`SIM116`) ([#​19111](https://redirect.github.com/astral-sh/ruff/pull/19111)) - \[`flake8-type-checking`] Make example error out-of-the-box (`TC001`) ([#​19151](https://redirect.github.com/astral-sh/ruff/pull/19151)) - \[`flake8-use-pathlib`] Make example error out-of-the-box (`PTH210`) ([#​19189](https://redirect.github.com/astral-sh/ruff/pull/19189)) - \[`pycodestyle`] Make example error out-of-the-box (`E272`) ([#​19191](https://redirect.github.com/astral-sh/ruff/pull/19191)) - \[`pycodestyle`] Make example not raise unnecessary `SyntaxError` (`E114`) ([#​19190](https://redirect.github.com/astral-sh/ruff/pull/19190)) - \[`pydoclint`] Make example error out-of-the-box (`DOC501`) ([#​19218](https://redirect.github.com/astral-sh/ruff/pull/19218)) - \[`pylint`, `pyupgrade`] Fix syntax errors in examples (`PLW1501`, `UP028`) ([#​19127](https://redirect.github.com/astral-sh/ruff/pull/19127)) - \[`pylint`] Update `missing-maxsplit-arg` docs and error to suggest proper usage (`PLC0207`) ([#​18949](https://redirect.github.com/astral-sh/ruff/pull/18949)) - \[`flake8-bandit`] Make example error out-of-the-box (`S412`) ([#​19241](https://redirect.github.com/astral-sh/ruff/pull/19241)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4yMy4yIiwidXBkYXRlZEluVmVyIjoiNDEuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW50ZXJuYWwiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [astral-sh/ruff-pre-commit](https://redirect.github.com/astral-sh/ruff-pre-commit) | repository | patch | `v0.12.2` -> `v0.12.3` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. Note: The `pre-commit` manager in Renovate is not supported by the `pre-commit` maintainers or community. Please do not report any problems there, instead [create a Discussion in the Renovate repository](https://redirect.github.com/renovatebot/renovate/discussions/new) if you have any questions. --- ### Release Notes <details> <summary>astral-sh/ruff-pre-commit (astral-sh/ruff-pre-commit)</summary> ### [`v0.12.3`](https://redirect.github.com/astral-sh/ruff-pre-commit/releases/tag/v0.12.3) [Compare Source](https://redirect.github.com/astral-sh/ruff-pre-commit/compare/v0.12.2...v0.12.3) See: https://github.com/astral-sh/ruff/releases/tag/0.12.3 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4yMy4yIiwidXBkYXRlZEluVmVyIjoiNDEuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW50ZXJuYWwiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [toml](https://redirect.github.com/toml-rs/toml) | workspace.dependencies | minor | `0.8.11` -> `0.9.0` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>toml-rs/toml (toml)</summary> ### [`v0.9.2`](https://redirect.github.com/toml-rs/toml/compare/toml-v0.9.1...toml-v0.9.2) [Compare Source](https://redirect.github.com/toml-rs/toml/compare/toml-v0.9.1...toml-v0.9.2) ### [`v0.9.1`](https://redirect.github.com/toml-rs/toml/compare/toml-v0.9.0...toml-v0.9.1) [Compare Source](https://redirect.github.com/toml-rs/toml/compare/toml-v0.9.0...toml-v0.9.1) ### [`v0.9.0`](https://redirect.github.com/toml-rs/toml/compare/toml-v0.8.23...toml-v0.9.0) [Compare Source](https://redirect.github.com/toml-rs/toml/compare/toml-v0.8.23...toml-v0.9.0) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4yMy4yIiwidXBkYXRlZEluVmVyIjoiNDEuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW50ZXJuYWwiXX0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
…ith uppercase names (`N802`) (#18907) Co-authored-by: Micha Reiser <micha@reiser.io>
## Summary Adds a way to list all members of an `Enum` and implements almost all of the mechanisms by which members are distinguished from non-members ([spec](https://typing.python.org/en/latest/spec/enums.html#defining-members)). This has no effect on actual enums, so far. ## Test Plan New Markdown tests using `ty_extensions.enum_members`.
Basically, we weren't quite using `Type::member` in every case correctly. Specifically, this example from @sharkdp: ``` class Meta(type): @Property def meta_attr(self) -> int: return 0 class C(metaclass=Meta): ... C.<CURSOR> ``` While we would return `C.meta_attr` here, we were claiming its type was `property`. But its type should be `int`. Ref #19216 (comment)
## Summary This PR removes the `FileLookupError` as it's not really required. The original intention was that this would be returned from the `.file` lookup to the different handlers but we've since moved the logic of "lookup file and add trace message if file unavailable with the reason" under the `file_ok` method which all of the handlers use.
I used a script to attempt to identify those rules with the following property: changing f-strings to t-strings in the corresponding fixture altered the number of lint errors emitted. In other words, those rules for which f-strings and t-strings are not treated the same in the current implementation. This PR documents the subset of such rules where this is fine and no changes need to be made to the implementation of the rule. Mostly these are the rules where it is relevant that an f-string evaluates to type `str` at runtime whereas t-strings do not. In theory many of these fixtures are not super necessary - it's unlikely t-strings would be used for most of these. However, the internal handling of t-strings is tightly coupled with that of f-strings, and may become even more so as we implement the upcoming changes due to python/cpython#135996 . So I'd like to keep these around as regression tests. Note: The `flake8-bandit` fixtures were already added during the original t-string implementation. | Rule(s) | Reason | | --- | --- | | [`unused-method-argument` (`ARG002`)](https://docs.astral.sh/ruff/rules/unused-method-argument/#unused-method-argument-arg002) | f-strings exempted for msg in `NotImplementedError` not relevant for t-strings | | [`logging-f-string` (`G004`)](https://docs.astral.sh/ruff/rules/logging-f-string/#logging-f-string-g004) | t-strings cannot be used here | | [`f-string-in-get-text-func-call` (`INT001`)](https://docs.astral.sh/ruff/rules/f-string-in-get-text-func-call/#f-string-in-get-text-func-call-int001) | rule justified by eager evaluation of interpolations | | [`flake8-bandit`](https://docs.astral.sh/ruff/rules/#flake8-bandit-s)| rules justified by eager evaluation of interpolations | | [`single-string-slots` (`PLC0205`)](https://docs.astral.sh/ruff/rules/single-string-slots/#single-string-slots-plc0205) | t-strings cannot be slots in general | | [`unnecessary-encode-utf8` (`UP012`)](https://docs.astral.sh/ruff/rules/unnecessary-encode-utf8/#unnecessary-encode-utf8-up012) | cannot encode t-strings | | [`no-self-use` (`PLR6301`)](https://docs.astral.sh/ruff/rules/no-self-use/#no-self-use-plr6301) | f-strings exempted for msg in NotImplementedError not relevant for t-strings | | [`pytest-raises-too-broad` (`PT011`)](https://docs.astral.sh/ruff/rules/pytest-raises-too-broad/) / [`pytest-fail-without-message` (`PT016`)](https://docs.astral.sh/ruff/rules/pytest-fail-without-message/#pytest-fail-without-message-pt016) / [`pytest-warns-too-broad` (`PT030`)](https://docs.astral.sh/ruff/rules/pytest-warns-too-broad/#pytest-warns-too-broad-pt030) | t-strings cannot be empty or used as messages | | [`assert-on-string-literal` (`PLW0129`)](https://docs.astral.sh/ruff/rules/assert-on-string-literal/#assert-on-string-literal-plw0129) | t-strings are not strings and cannot be empty | | [`native-literals` (`UP018`)](https://docs.astral.sh/ruff/rules/native-literals/#native-literals-up018) | t-strings are not native literals |
## Summary Previously, the virtual files were being added to the default database that's present on the session. This is wrong because the default database is for any files that don't belong to any project i.e., they're outside of any projects managed by the server. Virtual files are neither part of the project nor it is outside the projects. This was not the intention as in the initial version, virtual files were being added to the only project database managed by the server. This PR fixes this by reverting back to the original behavior where virtual files will be added to the only project database present. When support for multiple workspace and project is added, this will require updating (astral-sh/ty#794). This is required for #19264 because workspace diagnostics doesn't check the default project database yet. Ideally, the default db should be checked as well. The implementation of this PR means that virtual files are now being included for workspace diagnostics but it doesn't work completely e.g., if I save an untitled file the diagnostics disappears but it doesn't appear back for the (now) saved file on disk as shown in the following video demonstration: https://github.com/user-attachments/assets/123e8d20-1e95-4c7d-b7eb-eb65be8c476e
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary Part of #18972 This PR makes [implicit-cwd(FURB177)](https://docs.astral.sh/ruff/rules/implicit-cwd/)'s example error out-of-the-box. [Old example](https://play.ruff.rs/a0bef229-9626-426f-867f-55cb95ee64d8) ```python cwd = Path().resolve() ``` [New example](https://play.ruff.rs/bdbea4af-e276-4603-a1b6-88757dfaa399) ```python from pathlib import Path cwd = Path().resolve() ``` <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
## Summary Part of #18972 This PR makes [for-loop-writes (FURB122)](https://docs.astral.sh/ruff/rules/for-loop-writes/#for-loop-writes-furb122)'s example error out-of-the-box. I also had to re-name the second case's variables to get both to raise at the same time, I suspect because of limitations in ruff's current semantic model. New names subject to bikeshedding, I just went with the least effort `_b` for binary suffix. [Old example](https://play.ruff.rs/19e8e47a-8058-4013-aef5-e9b5eab65962) ```py with Path("file").open("w") as f: for line in lines: f.write(line) with Path("file").open("wb") as f: for line in lines: f.write(line.encode()) ``` [New example](https://play.ruff.rs/e96b00e5-3c63-47c3-996d-dace420dd711) ```py from pathlib import Path with Path("file").open("w") as f: for line in lines: f.write(line) with Path("file").open("wb") as f_b: for line_b in lines_b: f_b.write(line_b.encode()) ``` The "Use instead" section was also modified similarly. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
Co-authored-by: typeshedbot <> Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
…D201`, `D202`) (#19246) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> This PR fixes #7172 by suppressing the fixes for [docstring-missing-returns (DOC201)](https://docs.astral.sh/ruff/rules/docstring-missing-returns/#docstring-missing-returns-doc201) / [docstring-extraneous-returns (DOC202)](https://docs.astral.sh/ruff/rules/docstring-extraneous-returns/#docstring-extraneous-returns-doc202) if there is a surrounding line continuation character `\` that would make the fix cause a syntax error. To do this, the lints are changed from `AlwaysFixableViolation` to `Violation` with `FixAvailability::Sometimes`. In the case of `DOC201`, the fix is not given if the non-break line ends in a line continuation character `\`. Note that lines are iterated in reverse from the docstring to the function definition. In the case of `DOC202`, the fix is not given if the docstring ends with a line continuation character `\`. ## Test Plan <!-- How was it tested? --> Added a test case.
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of #18972 Fixes #14346 This PR makes [bidirectional-unicode (PLE2502)](https://docs.astral.sh/ruff/rules/bidirectional-unicode/#bidirectional-unicode-ple2502)'s example error out-of-the-box, by converting it to use one of the test cases. The documentation in general is also updated to replace "bidirectional unicode character" with "bidirectional formatting character", as those are the only ones checked for, and the "unicode" suffix is redundant. The new example section looks like this: <img width="1074" height="264" alt="image" src="https://github.com/user-attachments/assets/cc1d2cb4-b590-4f20-a4d2-15b744872cdd" /> The "References" section link is also updated to reflect the rule's actual behavior. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.1)
Can you help keep this open source service alive? 💖 Please sponsor : )