Commit Graph

72 Commits

Author SHA1 Message Date
Mikhail Golubev
9300fe8c45 PY-60104 Clean up in tests about type inference for decorators
Removed a number of tests in Py3TypeTest duplicating those of PyDecoratedFunctionTypeProviderTest.

Removed the tests about PY-23067 in Py3ArgumentListInspectionTest and Py3CompletionTest because
this issue was actually not addressed in 05e8ed4df0c7faa24bd972e1b422f664d708b510, and the behavior
some of them assert is not what users wanted.

More consistent naming of tests in PyDecoratedFunctionTypeProviderTest and PyParameterInfoTest.
Removed there excess tests too similar to others or checking scenarios not relevant to
the current approach to type inference for decorators, e.g. presense of @functools.wraps and
alternatives inside decorators — we don't even analyze their bodies anymore.

Add a few extra tests illustrating problems with the current approach:
- testNotAnnotatedDecoratorChangingFunctionSignatureIsIgnored
- testInStackOfDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testInStackOfImportedDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testNotAnnotatedDecoratorRetainsParametersOfOriginalFunctionEvenIfItChangesItsSignature

GitOrigin-RevId: 0bf5070fc523b88dcc9d3009786dd028bdfa0feb
2024-01-09 20:49:13 +00:00
andrey.matveev
52f21cc60d PY-48338 PY-60104 Make decorators pure functions if not annotated
GitOrigin-RevId: fed5c22c9114a5dcfb882be367c570baf8ba3e5a
2024-01-09 20:49:13 +00:00
lada.gagina
4061c6e187 PY-61139 Do not infer LiteralString for parameters with str default value
(cherry picked from commit 80992fa5d2d3e393326e4f469fe3bd6472f70643)

IJ-MR-112631

GitOrigin-RevId: ebbe6c433c4536660c7ccbe8462f16667a75c434
2023-11-07 22:10:30 +00:00
Irina Fediaeva
cbac1efb4c PY-49946: Mark errors in non-working test cases and mute them
GitOrigin-RevId: 4ca439c05c9325646f191073b9cba58988b8d161
2023-04-12 17:59:48 +00:00
Irina Fediaeva
7379dc43c5 PY-49946: Support 'kw_only' in @dataclass args and dataclasses.field() args
GitOrigin-RevId: fe6f32a2cb8fa65b122968e1e9cf9d2126f92398
2023-04-12 17:59:46 +00:00
Elizaveta Shashkova
a3af1d900c PY-46053 Huge Parameter Info popup
GitOrigin-RevId: 039b51b225ec6eb20b77305b47cc71d180398c79
2022-10-15 00:15:54 +00:00
Mikhail Golubev
84c48c48a9 PY-47532 Support new API and namespace of "attrs" package
GitOrigin-RevId: a8a0f909b21cc9f3b95a7b823452599374a943a9
2022-08-18 16:13:12 +00:00
Mikhail Golubev
63461fb262 PY-53671 Don't treat methods qualified with a module as unbound
While resolving an aliased method exported from a module, we might lose
the context that it was referenced via instance and hence its first "self"
parameter is already bound and doesn't need to be passed explicitly.
The reason is PyResolveUtil#doResolveQualifiedNameInScope (called in
PyTargetExpressionImpl.multiResolveAssignedValue) performs resolve
over qualified names saved in PSI stubs and returns plain PsiElements
(end results) that don't retain such information about their qualifiers.
QualifiedResolveResult can't be used there either because we don't keep
PyExpressions in PSI stubs. What's more, when later such function is referenced
via some module we consider it definitely unbound, even though a module cannot
possibly have a method as its immediate attribute. I changed the logic so that
we no longer consider referencing a method through a module as somehow affecting
its bound/unbound state.

GitOrigin-RevId: 17a6c3e5d43c088d0663ba54651004c8370d5eca
2022-07-19 15:06:06 +00:00
lada.gagina
6bdc3d4237 PY-53611 Add support of Required and NotRequired TypedDict type specifications (PEP-655)
Makes it possible to mark individual TypedDict keys as required or not required, covered in [PEP-655](https://peps.python.org/pep-0655/)

GitOrigin-RevId: 6567fd1009430e37f32924eb29ab8b4a1a17f315
2022-06-21 20:29:34 +00:00
Semyon Proshev
049680d7cf Remove dataclasses.py from test data after enabling corresponding pyi stub from typeshed
GitOrigin-RevId: fbb411d4ee07c3119e9c03892f5b3001d9e44a20
2021-08-19 17:20:30 +00:00
Semyon Proshev
6fcdc21997 Support type inference for cls inside namedtuple's class methods (PY-30870, PY-33140, PY-45473)
GitOrigin-RevId: a299d681d20230acd9443f0fa37c7fd64a51d76a
2020-11-18 18:45:09 +00:00
Semyon Proshev
53df3275e4 Use map function that takes implicit offset from callable type (PY-42205)
Since inner resolve function provides correct offset.

GitOrigin-RevId: 3e882c47537f16968fe6c5ba27475f9e1debc4d4
2020-07-09 12:08:10 +00:00
Semyon Proshev
327f9cbffd Support kw_only in attr.ib (PY-33189)
GitOrigin-RevId: 7354162dc40909842f95f9eb5c9e6b507c544ac8
2020-06-16 02:00:57 +03:00
Semyon Proshev
64470fd40d Don't add an ancestor's field as a parameter if it was overridden with init=False (PY-35548)
GitOrigin-RevId: 75b1a1c3d1852b98a58d066d6380f04e5dd013bd
2019-12-05 14:31:31 +00:00
Semyon Proshev
26d590e73a Fix processing inherited attributes with defaults provided from decorated methods (PY-34798)
GitOrigin-RevId: c4c265201218130ce2cac1611cd514e57d29fd8a
2019-12-04 15:33:19 +00:00
Semyon Proshev
1efa876ad0 Support kw_only in attr.s (PY-34374)
GitOrigin-RevId: a8e78103f3373c967cd429b21e0ced0d530b468d
2019-12-04 12:33:00 +00:00
Semyon Proshev
9ef2a6f638 Update parsing of attr.s for all the changes introduced in 19.2.0 and before (PY-36113, PY-38400)
GitOrigin-RevId: 11db701c16986bc8704f139f60a85f5b9c32a509
2019-12-04 12:33:00 +00:00
Lada Gagina
0f51507660 Add tests and fixes to TypedDict support
PY-38422 Unify warning message for 'clear' and 'popitem' TypedDict methods
PY-38505 Infer proper type for TypedDict subscription expressions
PY-38439 Fix TypedDict consistency check
PY-38415 Fix TypedDict keys order in parameter info
PY-38413 Add * before all arguments in TypedDict parameter hint
PY-38873 Fix detection of TypedDict subscription expression type when value is a dict, Dict or TypedDict

GitOrigin-RevId: 25ff441042f2e2d7791e28632a5016fb367685df
2019-11-22 21:03:15 +00:00
Semyon Proshev
6f6b19252c Fix processing mixed dataclass hierarchy when non-dataclass has __init__ (PY-28506, PY-31762, PY-33173) 2018-12-28 12:41:07 +03:00
Semyon Proshev
a349fad10c Fix processing attributes that override ancestors' ones (PY-28506, PY-31762) 2018-12-28 12:41:07 +03:00
Semyon Proshev
572023d293 Provide types for dataclasses in hierarchies (PY-28506, PY-31762, PY-33164) 2018-12-28 12:41:07 +03:00
Semyon Proshev
49ad069d76 Skip dataclass's fields that are not annotated (PY-29645) 2018-10-25 13:45:01 +03:00
Semyon Proshev
cef21f2445 Fix provided type for namedtuple._replace when receiver is namedtuple definition (PY-27148) 2018-10-15 16:46:55 +03:00
Semyon Proshev
ecb99048f0 Provide callable type for cls parameter (PY-28442) 2018-05-29 16:50:04 +03:00
Semyon Proshev
fe699ce721 Support initialization attrs attribute via name.default (PY-26354) 2018-05-29 16:49:56 +03:00
Semyon Proshev
8114d5ff07 Support private attrs attributes in __init__ and assoc/evolve (PY-26354) 2018-05-29 16:49:56 +03:00
Semyon Proshev
15e6a67c21 Provide special type for assoc/evolve usages on attrs (PY-26354) 2018-05-29 16:49:55 +03:00
Semyon Proshev
33f8bd2143 Support attr aliases for classes and fields (PY-26354) 2018-05-29 16:49:52 +03:00
Semyon Proshev
7261e9121a Support attrs fields defined via ib function (PY-26354) 2018-05-29 16:49:52 +03:00
Semyon Proshev
a65124d167 Support initializing attrs using PEP-526 (PY-26354)
Implement `attr.s` usage parsing
Enable `attr` stubs
2018-05-29 16:49:51 +03:00
Semyon Proshev
c1abea5187 Provide special type for typing.TypeVar as a callee (PY-28127) 2018-04-27 19:57:14 +03:00
Semyon Proshev
f5550fbc81 Provide special type for replace usages on dataclasses (PY-28957) 2018-03-20 14:20:25 +03:00
Semyon Proshev
29f70e9815 Sync dataclass parsing and testdata with March 04, 2018 changes in PEP-557 (PY-28957) 2018-03-20 14:20:23 +03:00
Semyon Proshev
bdce6311ca Support dataclasses fields defined via field function (PY-27398)
Update PyDataclassesTypeProvider to ignore such fields or correctly specify default value for them.
Create custom target stubs for such fields to store parameters.
2018-01-22 22:52:08 +03:00
Semyon Proshev
12341747ff Info on positional parameters when they are not expected (EA-102450) 2018-01-17 22:06:36 +03:00
Semyon Proshev
bafc005066 Full type support for namedtuple._replace (PY-27148)
Provide correct parameters for typed and untyped NT.
Clarify return type for untyped case.
2018-01-17 22:06:35 +03:00
Semyon Proshev
4fc97d088f Correct types for initvars in __init__ (PY-27398) 2018-01-09 14:39:27 +03:00
Semyon Proshev
92a6ae8a26 Ignore classvars when constructing virtual __init__ (PY-27398) 2018-01-09 14:39:26 +03:00
Semyon Proshev
b6982b4425 Support @dataclass(init=True/False) (PY-27398) 2018-01-09 14:39:23 +03:00
Semyon Proshev
3316258201 Provide callable type for dataclass initialization (PY-27398)
Add `dataclasses` to stdlib_packages.txt
2018-01-09 14:39:22 +03:00
Semyon Proshev
89a9b2c4ca Ability to filter types in parameter presentable text (PY-26582) 2017-12-04 19:28:50 +03:00
Semyon Proshev
49b4dec281 PY-24930 Fixed: False negative: no parameter info when implicitly calling __call__
Update PyCallExpressionHelper to support a case when callee resolves to call expression and this call expression returns class with `__call__`.
2017-07-03 17:50:38 +03:00
Semyon Proshev
2447451dc4 PY-24099 Fixed: False positive: parameter unfilled for NamedTuple with default value
Update PyCallableParameterImpl to be able to store default value and use this in PyNamedTupleType.
Class inherited from typing.NamedTuple passes default values to PyNamedTupleType.
2017-06-09 21:29:12 +03:00
Semyon Proshev
0c1b24d413 PY-23239 Fixed: NamedTuples aren't getting their types checked
PY-23253 Fixed: NamedTuple subclass inspection

Update PyNamedTupleType and PyNamedTupleStub to store fields' types.
Parameter hints show expected types and PyTypeCheckerInspection verifies them correctly.
2017-06-09 21:29:11 +03:00
Semyon Proshev
07fb8fca0a PY-4344 Fixed: Parameter unfilled: false negatives for named tuples
PY-22102 Fixed: NamedTuple class declaration for Python 3.6 not supported by PyCharm
PY-22249 Fixed: Add parameters tooltip to namedtuple constructor
PY-22740 Fixed: Unexpected argument for field names of class inherited from namedtuple

Update PyNamedTupleType to be callable and provide parameters when creating new namedtuple instance.
Update PyStdlibTypeProvider to provide special callable types when creating new namedtuple inheritor instance.
Update PyCallExpressionHelper to check type providers when resolving callee.
Update PyClassImpl to return PyNamedTupleType when class inherits typing.NamedTuple.

Parameter hints and PyArgumentListInspection work correctly with creating new namedtuple instances.
2017-06-09 21:29:11 +03:00
Semyon Proshev
edb827e655 Resolve callee to its type and then to its callable if possible.
It allows to calculate arguments-to-parameters mapping for types that don't have psi callable (i.e. typing.Callable).
Update PyParameterInfoHandler to work with callable types instead of callables.
2017-06-09 21:29:08 +03:00
Semyon Proshev
45321db0ac PY-23625 Fixed: Incorrect default argument value in print() function
Escape non-printable characters in parameter's default value.
2017-06-09 17:02:28 +03:00
Semyon Proshev
f0ab4154ef PY-22971 Fixed: Support @typing.overload in regular Python files, not only in Python stubs
Update PyReferenceImpl to resolve to the latest definition of the callable and prepend it with overloads.
Update PyParameterInfoHandler and PyTypeChecker to take into account overloads only if they exist.
2017-05-13 00:17:45 +03:00
Semyon Proshev
e8aeb6b502 PY-23055 Fixed: Default value of None is not shown in the parameter info popup
Show `None` default value when type was not inferred.
2017-03-14 14:40:06 +03:00
Semyon Proshev
8071da55be Add tests for PyParameterInfoHandler about overloads in imported module 2017-02-22 15:23:26 +03:00