-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[ruff] Extend FA102 with listed PEP 585-compatible APIs
#20659
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7f72452
Extend FA102 with `collections.abc` types
terror 1bc0af4
Re-use existing function
terror 7952f5f
Switch over to PR link
terror 37c531c
Split FA102 test coverage
terror 021910a
Inline `has_pep_585_generic`
terror 0911736
Extend rule to include preview generics
terror d261d3f
Consolidate test
terror 6bf1a66
Replace old test
terror File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...sources/test/fixtures/flake8_future_annotations/no_future_import_uses_preview_generics.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import asyncio | ||
| import collections | ||
| import contextlib | ||
| import dataclasses | ||
| import functools | ||
| import os | ||
| import queue | ||
| import re | ||
| import shelve | ||
| import types | ||
| import weakref | ||
| from collections.abc import ( | ||
| AsyncGenerator, | ||
| AsyncIterable, | ||
| AsyncIterator, | ||
| Awaitable, | ||
| ByteString, | ||
| Callable, | ||
| Collection, | ||
| Container, | ||
| Coroutine, | ||
| Generator, | ||
| Iterable, | ||
| Iterator, | ||
| ItemsView, | ||
| KeysView, | ||
| Mapping, | ||
| MappingView, | ||
| MutableMapping, | ||
| MutableSequence, | ||
| MutableSet, | ||
| Reversible, | ||
| Sequence, | ||
| Set, | ||
| ValuesView, | ||
| ) | ||
|
|
||
|
|
||
| def takes_preview_generics( | ||
| future: asyncio.Future[int], | ||
| task: asyncio.Task[str], | ||
| deque_object: collections.deque[int], | ||
| defaultdict_object: collections.defaultdict[str, int], | ||
| ordered_dict: collections.OrderedDict[str, int], | ||
| counter_obj: collections.Counter[str], | ||
| chain_map: collections.ChainMap[str, int], | ||
| context_manager: contextlib.AbstractContextManager[str], | ||
| async_context_manager: contextlib.AbstractAsyncContextManager[int], | ||
| dataclass_field: dataclasses.Field[int], | ||
| cached_prop: functools.cached_property[int], | ||
| partial_method: functools.partialmethod[int], | ||
| path_like: os.PathLike[str], | ||
| lifo_queue: queue.LifoQueue[int], | ||
| regular_queue: queue.Queue[int], | ||
| priority_queue: queue.PriorityQueue[int], | ||
| simple_queue: queue.SimpleQueue[int], | ||
| regex_pattern: re.Pattern[str], | ||
| regex_match: re.Match[str], | ||
| bsd_db_shelf: shelve.BsdDbShelf[str, int], | ||
| db_filename_shelf: shelve.DbfilenameShelf[str, int], | ||
| shelf_obj: shelve.Shelf[str, int], | ||
| mapping_proxy: types.MappingProxyType[str, int], | ||
| weak_key_dict: weakref.WeakKeyDictionary[object, int], | ||
| weak_method: weakref.WeakMethod[int], | ||
| weak_set: weakref.WeakSet[int], | ||
| weak_value_dict: weakref.WeakValueDictionary[object, int], | ||
| awaitable: Awaitable[int], | ||
| coroutine: Coroutine[int, None, str], | ||
| async_iterable: AsyncIterable[int], | ||
| async_iterator: AsyncIterator[int], | ||
| async_generator: AsyncGenerator[int, None], | ||
| iterable: Iterable[int], | ||
| iterator: Iterator[int], | ||
| generator: Generator[int, None, None], | ||
| reversible: Reversible[int], | ||
| container: Container[int], | ||
| collection: Collection[int], | ||
| callable_obj: Callable[[int], str], | ||
| set_obj: Set[int], | ||
| mutable_set: MutableSet[int], | ||
| mapping: Mapping[str, int], | ||
| mutable_mapping: MutableMapping[str, int], | ||
| sequence: Sequence[int], | ||
| mutable_sequence: MutableSequence[int], | ||
| byte_string: ByteString[int], | ||
| mapping_view: MappingView[str, int], | ||
| keys_view: KeysView[str], | ||
| items_view: ItemsView[str, int], | ||
| values_view: ValuesView[int], | ||
| ) -> None: | ||
| ... |
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
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
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
36 changes: 36 additions & 0 deletions
36
...s__flake8_future_annotations__tests__fa102_no_future_import_uses_preview_generics.py.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs | ||
| --- | ||
| FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| --> no_future_import_uses_preview_generics.py:42:19 | ||
| | | ||
| 40 | future: asyncio.Future[int], | ||
| 41 | task: asyncio.Task[str], | ||
| 42 | deque_object: collections.deque[int], | ||
| | ^^^^^^^^^^^^^^^^^^^^^^ | ||
| 43 | defaultdict_object: collections.defaultdict[str, int], | ||
| 44 | ordered_dict: collections.OrderedDict[str, int], | ||
| | | ||
| help: Add `from __future__ import annotations` | ||
| 1 + from __future__ import annotations | ||
| 2 | import asyncio | ||
| 3 | import collections | ||
| 4 | import contextlib | ||
| note: This is an unsafe fix and may change runtime behavior | ||
|
|
||
| FA102 [*] Missing `from __future__ import annotations`, but uses PEP 585 collection | ||
| --> no_future_import_uses_preview_generics.py:43:25 | ||
| | | ||
| 41 | task: asyncio.Task[str], | ||
| 42 | deque_object: collections.deque[int], | ||
| 43 | defaultdict_object: collections.defaultdict[str, int], | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 44 | ordered_dict: collections.OrderedDict[str, int], | ||
| 45 | counter_obj: collections.Counter[str], | ||
| | | ||
| help: Add `from __future__ import annotations` | ||
| 1 + from __future__ import annotations | ||
| 2 | import asyncio | ||
| 3 | import collections | ||
| 4 | import contextlib | ||
| note: This is an unsafe fix and may change runtime behavior |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.