1625 Commits
Author SHA1 Message Date
Morgan Bartholomew bcbdea3af7 [python] PY-76845 NamedTuple compatible with tuple
(cherry picked from commit 7f317902f2df8f5cb099924b42b2b08aaaa724fd)

IJ-MR-164103

GitOrigin-RevId: 91cecc5360756f222d62f9555cae6370281b8e6f
2025-06-03 11:25:30 +00:00
Petr 0ff784051a PY-80565 False warning auto not assignable to StrEnum
(cherry picked from commit 6e9bf2dad1ca9d421d433def0d1c323a1fd3b301)

GitOrigin-RevId: d01ee3e16a8622ce0aa788b246bad7ff102f42de
2025-05-28 19:28:39 +00:00
Daniil Kalinin f1be127202 PY-79967 Add a test for t-string in PyCompatibilityInspectionTest
(cherry picked from commit e431991078a31bd10e934a76e6446a5a5e30f816)

GitOrigin-RevId: da52cba702f089853b64e7687af4964443c53c48
2025-05-09 11:11:59 +00:00
Morgan Bartholomew fa4b4eec34 [pycharm] PY-41827 check for union types in PySimplifyBooleanCheckInspection
to avoid ambiguous conditions


(cherry picked from commit f11c08f8dfea453a6676173bae57f96233429970)

IJ-MR-159379

GitOrigin-RevId: b700b1e5e7c077da7b61661d33c2a3aa135d9e21
2025-05-01 02:46:56 +00:00
Petr 4a40e988e2 PY-76885 Conformance test failure: constructors_call_metaclass.py
Added multi-file test.

(cherry picked from commit e3105c8036c90b9571143ce7b2cc970813a5ed3b)

GitOrigin-RevId: fe9eae3be1de9d6c68525a239f52fba820c40c11
2025-04-23 23:27:31 +00:00
Petr c52f4bbadf PY-80195 Literals of Enums broken after import (2025.1 EAP)
Consider enum attribute of an unknown type an enum member.

(cherry picked from commit 72c2fd37f18e4dde65d735f1032495df5aeda791)

GitOrigin-RevId: 7e56afe6a2d2efe0ea84ac20672aaf7712d8ed23
2025-04-23 23:27:31 +00:00
Petr e1b380f8b9 PY-12132 Support ABC classes (pep-3119)
Report error for abstract method in non-abstract class.

(cherry picked from commit 824d45a310b95ada628d6e607ae1ced6e351d849)

GitOrigin-RevId: 446cfea2ab76611d13648c17d6f7419fdefa0954
2025-04-23 23:27:31 +00:00
Petr 42dd3f39bf PY-12132 Support ABC classes (pep-3119)
A class containing at least one method declared with `abstractmethod` decorator that hasn’t been overridden yet cannot be instantiated.

Also report instantiation of classes that directly inherit ABC or have metaclass set to ABCMeta.

(cherry picked from commit 55cb4dc90c55ddc63991a4c3f6b50b4e34a3b4bd)

GitOrigin-RevId: b37ea24490dc5ce7dcce87adf21aa6fe31e0e9dc
2025-04-23 23:27:31 +00:00
Petr 8fdd497e22 PY-12132 Support ABC classes (pep-3119)
Convert test files used with the default language level to Python 3 (PyAbstractInspectionTest)

(cherry picked from commit debae3365955d6237c423197ec25a638dbd95dfb)

GitOrigin-RevId: 66f17df6866682c5e18a6f43a861e628ddb0ba30
2025-04-23 23:27:31 +00:00
evgeny.bovykin 5cdec66645 PY-78250 Call PyDataclassTypeProvider before PyTypingTypeProvider so that it has a chance to infer the dataclass type first
(cherry picked from commit 18230af949275e3f585ce806fec25144731e347b)

IJ-MR-158112

GitOrigin-RevId: 50ed312ca85b506cd1a8e8411b80548f81b56487
2025-04-23 12:07:33 +00:00
Morgan Bartholomew 57b4491fda [pycharm] PY-79331 render type as "type", not "Type"
IJ-MR-159663

GitOrigin-RevId: e346f761a0c07e6f5897d02f6529ad78a073daa5
2025-04-16 08:37:21 +00:00
evgeny.bovykin 37d60f18fe PY-80147 Handle type of tuple expression being null in PyStringFormatInspection
It can be null if, for example, a Python interpreter is not configured and a tuple of strings is used as a rightExpression

(cherry picked from commit 23564503422a75de7b538dec3400fb8dd284cd73)

IJ-MR-159172

GitOrigin-RevId: 0bb36753d66f81afc784e88d8d7cd84b5795997c
2025-04-08 07:45:27 +00:00
Pavel Karateev 2c3f89d873 PY-79802 Fix tests
(cherry picked from commit e423287ff840e04cea0548fcc589d7b7dc37b105)

IJ-MR-157680

GitOrigin-RevId: 16494fb1755b181d31c1ec43752e8fa21a795d51
2025-03-26 12:41:47 +00:00
Timur Malanin dbdb988529 PY-54850 Normalized package names in PyPackageRequirementsInspection for consistent matching and refactored requirement satisfaction checks. Unified normalizePackageName logic. introduced a test to verify that requirement mismatch warnings disappear upon package installation.
GitOrigin-RevId: 11a4c70e26abcb4cb6d445016d8f68599666fb16
2025-03-22 14:02:34 +00:00
evgeny.bovykin 0060074133 PY-46623 Add setter and deleter to cached_property
(cherry picked from commit 97c7703a89d0e1c49f829aed3474006ac7e5324a)

GitOrigin-RevId: 266ec4f71c70550d06f1632005edfd008029298e
2025-03-19 18:57:08 +00:00
Alex Grönholm f39cf6739e PY-15985: Don't suggest replacing a chained assignment with an augmented assignment
(cherry picked from commit 6022b2b19e28b4ea424ee1022e07be328d636ad3)

GitOrigin-RevId: 2b38f6bebe2c02cd02725de78c7532c498676997
2025-03-06 21:48:52 +00:00
Aleksandr.Govenko e8f5b1c631 PY-52477 PY-78913 Add inspection for inconsistent returns
Merge-request: IJ-MR-154297
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: e89225212cc981a5b256fca4ee23d77659b3ce5e
2025-02-14 17:21:51 +00:00
Aleksandr.Govenko 6659947437 PY-51564 "code is unreachable" warning does not consider that context managers can abort
Added PyWithContextExitInstruction that works as 'except' node in try-except statements, but for 'with context-manager' statements. This allows to see when it can recover from exception by checking the type of `contextlib.AbstractContextManager`

Merge-request: IJ-MR-152213
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: fd5a139de31d47136cc86b4a7e090a20b73b8744
2025-02-14 13:18:20 +00:00
Alexey Kudravtsev e3895916cf show encoding problem for the whole file, instead of the empty string in the very beginning, for which quickfixes are hard to invoke
GitOrigin-RevId: 21a06256d25ea4cedac5bc812b41628e9fc2d985
2025-02-14 11:42:03 +00:00
Petr af57462aa7 PY-78653 Fix constrained type variable substitution
Subtypes of types constrained by a type variable should be treated as their respective explicitly listed base types in the context of the type variable.

GitOrigin-RevId: ecaac1614f66974b6e6c2217ac0a90321d049f76
2025-01-28 15:24:40 +00:00
Mikhail Golubev 3e7f5516bd PY-78662 PY-78663 Enable the "Unused local" inspection for type aliases and other scope owners
besides already supported classes, functions and lambdas.

GitOrigin-RevId: e70774af6b97e68ca82c47ac58b7b1421307b2d3
2025-01-24 22:48:25 +00:00
Alexander Kuklev 5da1a4c3fd [PY-33917] Added a test for the __init_subclass__ inspection issue
GitOrigin-RevId: 41879af7909785ae8a8b1f747aa77e0e3c3d7d9a
2025-01-20 16:13:26 +00:00
Andrey Vokin 7510fc1706 PY-78371 PyCharm does not mark imports in try/except blocks as unused
Update test data.
1. Unresolved imports are not removed with optimize imports
2. Unresolved imports are not marked as unused

GitOrigin-RevId: 2c32c368ae0907fb75ea76fc9749e903c160667c
2025-01-16 21:34:27 +00:00
Andrey Vokin 6521d75e87 PY-77891 "Unused import" inspection is inconsistent in nightly
The logic for disabling the unused warning on unresolved imports was dependent on the visit order. Moving sustracting unresolved imports to the end of computation fixes the problem.

GitOrigin-RevId: adeb85e59c17261a5bf9f64dfb4a7836a2403f43
2025-01-16 21:34:27 +00:00
Petr 90897b73b7 PY-78248 typed dict can be compatible with protocol types
GitOrigin-RevId: c19c0c68610718878b76ce5e149f0e1e1e642465
2025-01-07 21:44:59 +00:00
Mikhail Golubev 0b6e4a1488 PY-74114 Remove redundant "mock" library stubs from test data
These were added even before .pyi stubs for `mock` and `unittest.mock`
were enabled, so they have been unnecessary for a long while.

GitOrigin-RevId: 844667e63263fcc88cdda58e5140c6b59a6825af
2025-01-06 17:58:30 +00:00
Aleksandr.Govenko 0ef89717d7 PY-77988 Only report "Too broad exception clause" if reference expression is used
Merge-request: IJ-MR-152214
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: 6c820545d05ae09ce87e15458a265f779d385146
2025-01-01 16:55:15 +00:00
Petr ff36e2a969 PY-78248 TypedDict compatibility with dict
Dict cannot be assigned to TypedDict

GitOrigin-RevId: d635af6617b3c96ff89d9953473aaad115fa30a0
2024-12-24 14:12:27 +00:00
Petr 730c7ec335 PY-78248 TypedDict compatibility with dict
Merge Py3TypeCheckerInspectionTest.testTypedDictConsistencyWithDict into PyTypeCheckerInspectionTest.testTypedDictConsistency

GitOrigin-RevId: 75348ee7333cfd377503a56bbcc71dc11bee2de9
2024-12-24 14:12:27 +00:00
Petr d5f5d75ba2 [python] Exclude assert statements from PyFunction.getReturnPoints()
GitOrigin-RevId: 2dda1d8cd4c855a6c9e327e096586eb6b72823fe
2024-12-20 14:15:58 +00:00
Petr 3f8f4f40c3 [python] CFG support logical expressions in if/while conditions
GitOrigin-RevId: 274b3271dccc93be64830374c8047a8f6552033e
2024-12-19 19:51:11 +00:00
Petr 49b3258737 PY-76812 Conformance test failure: typeddicts_alt_syntax.py
Infer typed dict type from TypedDict() call even in case of an unexpected arguments list.

Also changed incorrect TypedDict() signature:
from (name: str, fields: dict[str, Any], total: bool = True) -> Any
to (typename: str, fields: dict[str, type], *, /, total: bool = True) -> Any

GitOrigin-RevId: 94c1ebb4fe3026744cb9771eab9e5ba507d049fa
2024-12-19 18:50:44 +00:00
Mikhail Golubev 93945dbb7a PY-73050 Remove hardcoded return types for open() functions
Now that we have proper support for Literal types and overloads,
we can infer the right return type automatically.

It breaks custom type inference for the "open" function in Python 2
because of their outdated stubs not using Literal type for the "mode"
argument. The stubs for Python 2 are no longer included in Typeshed,
so we keep an old snapshot of them. However, breaking it seems
acceptable nowadays, and if the need ever arises, we should better
customize our copy of .pyi stubs for Python 2.

GitOrigin-RevId: cd18252976959e81e2412f0433edc66e8e9ccfc5
2024-12-12 12:08:20 +00:00
Aleksandr.Govenko 582260c604 PY-37718 "This code is unreachable" after an 'assert False' a context manager
Treat 'assert False' like 'raise AssertionError'


Merge-request: IJ-MR-150462
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: d8d0a5e27d377362059a0d2a5e15aa730bdfb49a
2024-12-12 02:56:58 +00:00
Petr 5486d93839 PY-76841 Conformance test failure: dataclasses_postinit.py
__post_init__ parameters have to match InitVars type not name

GitOrigin-RevId: 0e1e4a9c3a50eee84cd724b5a3f8c5e894e90bdd
2024-12-11 20:51:44 +00:00
Mikhail Golubev 91986e49c5 PY-77433 Fix resolving qualified names in field_specifiers argument of @dataclass_transform
Previously, we mistakenly tried to resolve qualified names listed in the
`field_specifiers` argument of @dataclass_transform in the same scope
where the dataclass itself is defined, not where the actual decorator
application is located.

Thus, if in the file where the dataclass is defined, a field specifier
was imported differently than where @dataclass_transform was applied, we
couldn't recognize a field specifier call in the RHS of an assignment as such
and took it for an ordinary field default value.

In particular, this is what happened with pydantic dataclasses.
`pydantic.fields.Field` is usually imported as just `pydantic.Field` where
user dataclasses are defined, but imported with an alias and set in the
`field_specifiers` argument as `PydanticModelField` in
`pydantic._internal._model_construction` where `ModelMetaclass` is defined.

It was accidentally broken in f15a07836e7aeac7c46b489b4742e8248a0e6ef4 to
support decorating class methods with dataclass_transform
(see testData/inspections/PyDataclassInspection/DataclassTransformFieldsOrder/decorator.py).
Until PyResolveUtil.resolveQualifiedNameInScope automatically traverses through
containing scopes looking for a name, the file containing decorator application
seems like a safe trade-off for the scope, because field specifiers are normally
defined or imported somewhere at the top level.

GitOrigin-RevId: de9afeb0831a52f058453fe678de229d41c26a4d
2024-12-11 16:48:52 +00:00
Mikhail Golubev 0ee9369aa1 PY-77433 Don't report mutable field defaults in dataclass_transform-based dataclasses
Some dataclass implementations, such as Pydantic, allow declaring fields with
mutable defaults, deep-copying them under the hood.

See https://docs.pydantic.dev/latest/concepts/models/#fields-with-non-hashable-default-values

GitOrigin-RevId: e495621858950976226731dddbb01af4012704fa
2024-12-09 16:35:42 +00:00
Aleksandr.Govenko 80ea4e852c PY-20710 Support 'Generator' typing class
Check YieldType of yield expressions in PyTypeCheckerInspection
Check that (Async)Generator is used in (async) function
Check that in 'yield from' sync Generator is used
Convert PyMakeFunctionReturnTypeQuickFix into PsiUpdateModCommandAction
Infer Generator type for lambdas
When getting function type from annotation, do not convert Generator to AsyncGenerator
Introduce GeneratorTypeDescriptor to simplify working with generator annotations


Merge-request: IJ-MR-146521
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: b3b8182168c5224f0e03f54d443171ccf6ca7b89
2024-12-04 15:22:15 +00:00
Aleksandr.Govenko 31dd92576e PY-20611 Missing warning about functions implicitly returning None when return type is not Optional
Updated PyFunction to account for implicit 'return None' statements when inferring return statement types.

It affected return type inference of PyFunction.

Fixed a failing test related to formatted strings.

Added a quick fix to make all return statements explicit.

Updated the CFG to include PyPassStatements, enabling detection of exit points in empty functions.

Simplified PyMakeFunctionReturnTypeQuickFix to independently infer function types and handle required imports. Currently, it does not support specifying custom suggested types.



Merge-request: IJ-MR-148719
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: 9f58961f9eb70e4f9dbba7359f5aafdfd392b7e2
2024-11-26 17:02:37 +00:00
Petr 16d40e9c5d PY-76830 PY-76833 PY-76843 PY-76879 Enums support
GitOrigin-RevId: 9021c003cde70c39f8a5635b42761c08049490e2
2024-11-13 18:30:03 +00:00
Mikhail Golubev d522d4410a PY-36889 Type check assignments to class/instance attributes outside of class bodies
Previously, PyTypingTypeProvider.getReferenceType returned a type from a class attribute
type hint only for assignment to instance attribute located inside a class definition.

In other words, here we inferred the expected type from the annotation
and reported incompatible types in assignment:

```python
class C:
    attr: int

    def m(self):
        self.attr = "foo"
```
but in the following we didn't:

```python
class C:
    attr: int

inst = C()
inst.attr = "foo"
```

Now we try to resolve any qualified target expression to a class
or instance attribute and then infer the type from the corresponding
annotation.

GitOrigin-RevId: 086dbb678a8cd89cfe332bf801631568fb6c3a4d
2024-11-04 17:24:56 +00:00
Irina Fediaeva 01e08f43e4 PY-52574: Update tests after removing Epytext docstring format
GitOrigin-RevId: d4a90a8da56ca889cf380aa5bc72ac82b0716abc
2024-10-29 21:03:06 +00:00
Daniil Kalinin 8ddebc4e91 [python] dataclass_transform: use the annotated class as a resolve anchor for resolving the field specifiers
GitOrigin-RevId: f15a07836e7aeac7c46b489b4742e8248a0e6ef4
2024-10-28 08:26:47 +00:00
Mikhail Golubev e314e71e3c PY-42137 Report incorrect arguments if no overload matches
Previously, we reported call arguments only if either all callee
candidates have unmatched arguments or all call candidates have
unmatched parameters. When there was a mix of the two, we reported
nothing.

GitOrigin-RevId: 97b42faf10de74ee7cd10f934d9eb94e1c8bbb34
2024-10-15 22:19:26 +00:00
Mikhail Golubev 740771109f PY-54560 Fix handling of class-based field specifiers, add extra tests
GitOrigin-RevId: e411c00a4aeb12da59787c0273e678cab70b3e07
2024-09-09 23:17:25 +00:00
Mikhail Golubev d5bf0d0ae2 PY-54560 Fix typos in a test
GitOrigin-RevId: f544f217d7a59b62d3a2a793097e6021ea771f03
2024-09-09 23:17:24 +00:00
Andrey Vokin 7b9531711d PY-73263 Python 3.13 Support - Code Insight - Typeshed
Update testdata

GitOrigin-RevId: 73eca86671bcacd7efbdd305925abf1882590fd3
2024-09-09 13:54:00 +00:00
Andrey Vokin 1041f5e6a0 PY-73263 Python 3.13 Support - Code Insight - Typeshed
GitOrigin-RevId: 94973415b96b2a0f859d29b0201d1ccee0d06462
2024-09-09 13:54:00 +00:00
Mikhail Golubev aef3b8de3c PY-59198 PY-54560 Support "alias" parameter of attr and dataclass_transform fields
GitOrigin-RevId: 6a81d2a45d808391413b5c0b52c79f7f6c51dcbb
2024-09-09 11:34:15 +00:00
Mikhail Golubev 53d8170407 PY-59198 Update attr package stubs in test data
GitOrigin-RevId: 1292ba4fb7f39a2980b30c80d16811060f11509c
2024-09-09 11:34:15 +00:00