Commit Graph

5397 Commits

Author SHA1 Message Date
Eric Traut
2c9c42481f Removed vestigial code in Union type arg logic. 2024-08-10 23:05:27 -06:00
Eric Traut
fe3eca368a
Fixed bug that results in a confusing type in an error message when isinstance type narrowing between a type and another type creates a subclass. (#8741) 2024-08-10 18:32:46 -06:00
Eric Traut
142daa0a07
Removed some unnecessary special casing of None in type guard logic. (#8740) 2024-08-10 18:23:59 -06:00
Eric Traut
3905cfb852
Another round of simplification for callable return types. (#8737) 2024-08-10 13:26:07 -06:00
Eric Traut
2b82d07f69 Added small performance optimization in checker to avoid generating a diagnostic message in cases where it won't be used. 2024-08-10 12:42:17 -06:00
Eric Traut
913d18d960
Renamed some internal functions for readability and added options parameter to getEffectiveReturnType function. This is in preparation for a more involved change to fix #8723. (#8736) 2024-08-10 12:40:29 -06:00
Eric Traut
07ca233ba7 Updated typescript compiler version from 5.2 to 5.5.4 to avoid a bug I was hitting. 2024-08-10 10:58:10 -06:00
Eric Traut
1a17c0aa6b
Changed synthesized comparison methods (__lt__, etc.) for dataclasses when order=True to use Self rather than an instance of the class. This is not only more consistent with other synthesized methods, but it also preserves covariance of type variables if the dataclass is frozen. (#8734) 2024-08-10 10:27:32 -06:00
Eric Traut
465b04c80b Fixed a bug in the code that detects attribute docstrings to prevent it from walking all the way to the top of the parse tree. 2024-08-10 09:52:18 -06:00
Eric Traut
4fc5de5c1e
Fixed a false positive error when solving type variables in a call that involves a lambda. This addresses #8714. (#8730) 2024-08-10 00:47:49 -06:00
Rich Chiodo
f85e257026
Special case pythonPath to also come from the languageServer (#8728)
* Special case pythonPath to also come from the languageServer

* Compare URI correctly
2024-08-09 18:49:18 -06:00
Rich Chiodo
2aa9bf4c20
Reapply the compiler flags change but separate out the 'language server' specific settings (#8726)
* Document different types of 'compiler' flags and ensure merging of flags is consistent (#8704)

* Make sure config options cannot be overridden by settings.json

* Make sure extraPaths and python env information is updated from the command line

* Change fromVsCodeExtension to fromLanguageServer

* Separate command line options into json ones and language server ones

* Fix build error
2024-08-09 16:15:38 -07:00
Eric Traut
152350997d
Enhanced argument-to-parameter matching logic to support dictionary unpacking where the dict key type is a union of literals. This addresses #8671. (#8724) 2024-08-09 15:30:43 -06:00
Eric Traut
de0386d690 Revert "Document different types of 'compiler' flags and ensure merging of flags is consistent (#8704)"
This reverts commit a86210ccb7.
2024-08-09 13:20:55 -06:00
Eric Traut
421a87fd8a
Improved consistency of parameter name restrictions for the reportSelfClsParameterName check. Previously, different rules were applied to __new__ and class methods within metaclasses. This addresses #8717. (#8720) 2024-08-09 13:11:34 -06:00
Rich Chiodo
a86210ccb7
Document different types of 'compiler' flags and ensure merging of flags is consistent (#8704)
* Make sure config options cannot be overridden by settings.json

* Make sure extraPaths and python env information is updated from the command line

* Change fromVsCodeExtension to fromLanguageServer
2024-08-09 10:38:33 -07:00
Eric Traut
f68a616eb2 Fixed bug that produces signatures with extra (unnecessary) positional-only and keyword-only separators when using a TypedDict with zero fields. This addresses #8712. 2024-08-09 08:39:51 -06:00
Eric Traut
778509b20d Cleaned up some out-of-date comments and removed a circular import. 2024-08-09 00:24:02 -06:00
Eric Traut
55e1681568
Fixed bug that results in a false negative reportIncompatibleMethodOverride when the child class method uses a type parameter that is scoped to the child class. This addresses #8622. (#8711) 2024-08-09 00:04:00 -06:00
Eric Traut
fd68169161 Renamed PopulateExpectedType flag and clarified its purpose. 2024-08-08 19:32:59 -06:00
Eric Traut
77dc8848c5 Simplified internal validateArgTypes function. 2024-08-08 19:26:16 -06:00
Eric Traut
93115f9232
Renamed OverloadedFunctionType to OverloadedType for brevity and to reflect the fact that non-function types are now supported for overloads. No functional change, just a rename. (#8708) 2024-08-08 18:16:30 -06:00
Eric Traut
1d5420cb75
Further simplified TypeVar constraint tracking and solving. Removed the need to track separate constraints for dest and src. (#8707) 2024-08-08 17:58:48 -06:00
Eric Traut
3e448e7615
Fixed regression that resulted in a hang when determining whether an overload implementation with generics was compatible with its overloads. This addresses #8687. (#8706) 2024-08-08 17:29:08 -06:00
Kacie Kang
1f193580c8
Fix fileInfo null error (#8702)
* fix file info null reference

* check for binding

* removing fileinfo in if statement
2024-08-08 16:08:33 -07:00
Eric Traut
e8f0965e5b
Removed overly-complicated (and buggy) internal function setTypeArgsRecursive. (#8703) 2024-08-08 13:48:16 -06:00
Eric Traut
65ea3e95b4
Fixed bug that results in a false positive error when type argument for Literal doesn't follow type expression rules within a value expression context. This addresses 8696. (#8700) 2024-08-08 12:37:39 -06:00
Eric Traut
efda709120
Fixed a bug that results in a false positive reportInconsistentOverload error when the implementation of the overload includes a decorator that changes the type of the implementation to a non-function type. This addresses #8692. (#8699) 2024-08-08 12:26:27 -06:00
Eric Traut
2b603b9144
Modified OverloadedFunctionType interface in preparation for a follow-on change. Users of OverloadedFunctionType must now use the accessor functions to get the overloads and implementation. (#8695) 2024-08-08 09:32:21 -06:00
Eric Traut
8c628b0bc4 Fixed bug that results in a crash when an empty tuple is used to specialize a generic type alias parameterized by a ParamSpec. This addresses #8694. 2024-08-08 00:13:28 -06:00
Eric Traut
3d52679f59 Added optimization to shortcut overlapping overload checks if the diagnostic is suppressed. 2024-08-07 12:10:32 -06:00
Eric Traut
51c98aa945 Added small optimization that skips checks for overload consistency if these diagnostics are suppressed. 2024-08-07 12:06:15 -06:00
Eric Traut
f0c0dc8d4d Published 1.1.375 2024-08-06 20:32:59 -06:00
Eric Traut
e5889207ff Fixed bug that causes infinite recursion and memory exhaustion under certain circumstances involving recursive type aliases where the type alias is used as a type argument. This addresses #8670. 2024-08-06 16:39:26 -06:00
Eric Traut
1ab7801331
Fixed bug in type narrowing logic for value patterns, specifically when two enums with members of the same name are involved. This addresses #8674. (#8682) 2024-08-06 13:10:35 -06:00
Eric Traut
c285825dea
Allow Final and ClassVar to be combined in both directions within a dataclass. Previously, the Final qualifier needed to be the outermost. This addresses #8676. (#8678) 2024-08-06 11:44:51 -06:00
Eric Traut
08e02e450b
Added support for bool expansion to Literal[True] | Literal[False] during pattern matching when using value patterns. (#8677) 2024-08-06 11:11:47 -06:00
Eric Traut
c1df6595a1
Fixed a bug that results in incorrect type narrowing when using isinstance with an instance of a generic class as the first argument and a concrete subclass as the filter type. This addresses #8672. (#8675) 2024-08-06 10:30:12 -06:00
Eric Traut
35ab773671
Another round of simplification for TypeVar solving. Add support for recursive solutions (i.e. a TypeVar that has an upper or lower bound that depends on another TypeVar). (#8663) 2024-08-05 14:12:05 -06:00
Eric Traut
4d471f154f Updated typeshed stubs to the latest version. 2024-08-05 13:25:56 -06:00
Eric Traut
c10fa6d535
Fixed a bug that results in incorrect type narrowing for truthy/falsy type guards consisting of an Enum member when the enum class derives from ReprEnum. In this case, the "magic" of the enum implementation forwards the __bool__ call to the underlying value. This addresses #8658. (#8662) 2024-08-05 13:03:06 -06:00
Eric Traut
9a5643fc5f
Further simplified TypeVar constraint tracking and solving. Removed precomputed "lowerBoundNoLiterals" from tracker. (#8656) 2024-08-05 10:31:15 -06:00
Eric Traut
bf6eab2147
Fixed a bug that results in incorrect overload matching when one overload contains a zero-arity variant and another overload contains an *args (variadic) parameter. This addresses #8645. (#8654) 2024-08-05 01:34:02 -06:00
Eric Traut
4adf903331
Fixed bug that caused first argument of cast method on memoryview object to be treated as a type expression. Pyright was confusing this method with typing.cast. This addresses #8649. (#8651) 2024-08-04 14:49:43 -06:00
Eric Traut
fe0dc216f0
Fixed bug that results in a false positive error under certain circumstances when passing an overloaded function as an argument to a call. This addresses #8632. (#8644) 2024-08-03 01:12:51 -06:00
Eric Traut
ed65b44df3 Added subtyping support or IntEnum and StrEnum members. These literal values are subtypes of the corresponding literal int or str. This partly addresses #8641. 2024-08-02 23:01:20 -06:00
Eric Traut
24ed89d3ea Fixed bug in TypeVar auto-variance calculations for NamedTuples. Since NamedTuple variables are read-only, they should not cause a TypeVar to be invariant. 2024-08-02 18:46:35 -06:00
Eric Traut
d298d49981 Renamed constraint tracker method setConstraints to setBounds for clarity. 2024-08-02 14:36:19 -06:00
Eric Traut
c883ac067c Did a round of terminology cleanup for TypeVarTuples. No functional change. 2024-08-02 14:14:38 -06:00
Eric Traut
e22d2d2b1b
Did another round of simplification in the ParamSpec logic. (#8642) 2024-08-02 14:00:14 -06:00
Eric Traut
ce8c57f44d
Did a cleanup pass on the code that accesses the param types. Some code paths were not using the appropriate accessor functions, so they were ignoring specialized param types and using the unspecialized (declared) type instead. (#8640) 2024-08-02 12:55:33 -06:00
Eric Traut
5ad9f1fea1 Fixed bug that results in a false positive reportUnsupportedDunderAll warning when using the __all__.extend(x.__all__) form and the list of entries in x is empty. This addresses #8636. 2024-08-02 08:10:19 -06:00
Eric Traut
7802376828 Changed disableLanguageServices feature to apply to hover text as well as other language services. Previously, hover text was excluded. This addresses #8639. 2024-08-02 07:59:47 -06:00
Eric Traut
842ab02c34
Fixed bug in the functools.partial logic that results in incorrect handling of an unpacked TypedDict when used with a **kwargs parameter. This addresses #8617. (#8630) 2024-07-31 23:12:50 -07:00
Eric Traut
33d2937b8c
Removed constraint solving logic from constraint tracker. All such logic should be contained within the constraint solver. (#8629) 2024-07-31 18:40:15 -07:00
Eric Traut
327dcfc42a
Removed a bunch of redundant and special-case handling of param specs that's no longer needed. (#8627) 2024-07-31 16:29:23 -07:00
Eric Traut
2eb14cba65
Separated constraint solving from the application of the solved type variables. (#8624) 2024-07-31 12:37:50 -07:00
Eric Traut
d300291291
Fixed bug that leads to internal data structure corruption and subsequent false positive errors in certain cases involving unions of Unknown types that include type aliases. This addresses #8608. (#8621) 2024-07-31 09:35:50 -07:00
Eric Traut
7ba1c62bdc
Fixed bug that results in a false positive error when a covariant type variable that is scoped to a method is used in a parameter annotation. This addresses #8614. (#8615) 2024-07-30 22:24:27 -07:00
Eric Traut
5992d8aae2 Published 1.1.374 2024-07-30 21:12:50 -07:00
Eric Traut
7532c0f5ca
Type var cleanup10 (#8613)
* Renamed TypeVarContext to ConstraintTracker in preparation for further refactoring. No functional change.

* Did some code cleanup in the constraint solver module.
2024-07-30 21:10:56 -07:00
Eric Traut
0b7d2ca240 Fixed regression that results in a false negative when an illegal type expression form is used within a PEP 695 constrained TypeVar definition. 2024-07-30 16:14:45 -07:00
Eric Traut
45161ef964
Fixed bug that results in a false positive when using a two-argument form of super() outside of a class. This addresses #8604. (#8611) 2024-07-30 15:59:57 -07:00
Eric Traut
28600608a6
Next round of simplification. Removed higherOrderTypeVarScopeIds. (#8610) 2024-07-30 15:10:45 -07:00
Eric Traut
e1d377efcd
Another round of cleanup and simplification. (#8609) 2024-07-30 14:36:51 -07:00
Eric Traut
3e936c7720
Further simplified code for tracking type vars. (#8606) 2024-07-30 12:44:20 -07:00
Eric Traut
8b5c1da2b5
Further simplified and cleaned up type var application code. (#8605) 2024-07-30 11:39:31 -07:00
Eric Traut
6913347aa8
Fixed bug that results in false positive error under certain circumstances when solving type variables that involve literal values. This addresses #8133 and #8048. (#8603) 2024-07-30 10:48:06 -07:00
Eric Traut
74345cc15f
Further simplified code in type var application code. (#8601) 2024-07-30 10:13:22 -07:00
Eric Traut
c9543bc987
Further simplification of the logic involved in type var solving. (#8600)
This addresses #8301 and #5855.
2024-07-30 10:00:00 -07:00
Eric Traut
b629011afc Added small optimization for argument type checking that saves some memory and time. 2024-07-30 00:48:40 -07:00
Eric Traut
a82a7b972c
Did more cleanup of the "apply solved type var" code path. (#8598) 2024-07-29 22:50:49 -07:00
Eric Traut
c82019fec5
Renamed "external" and "internal" type vars to "free" and "bound" respectively. This terminology is more reflective of their true meaning. No functional change. (#8595) 2024-07-29 21:33:50 -07:00
Eric Traut
85651bd849 Renamed "in-scope placeholder type variables" to "unification variables". No functional change. 2024-07-29 20:59:05 -07:00
Eric Traut
67f0b8d173
Simplified some of the logic involved in type var constraint solving. (#8594) 2024-07-29 20:50:55 -07:00
Eric Traut
4d2d197bff
Started to simplify some of the code involved in type var solving. (#8590)
Improved handling of type variable matching when a callee's parameter is a union of two or more "naked" type variables (like `S | T`).
2024-07-29 17:30:33 -07:00
Eric Traut
173ced142d
Fixed bug that can result in a false positive when calling the constructor within a class that has unannotated __init__ or __new__ method parameters. (#8582) 2024-07-29 11:03:28 -07:00
Eric Traut
e99b7726c8
Fixed bug that can result in a false negative when a function return type is a TypeVar and the function falls through and implicitly returns a None. (#8581) 2024-07-29 10:46:58 -07:00
Eric Traut
c2f5d26f03
Adjusted the heuristics for constraint solving to favor solutions of type T over type[T]` when both are valid. (#8579) 2024-07-28 22:26:34 -07:00
Eric Traut
cfd1a3710a Fixed bugs in a few test cases. 2024-07-28 13:19:58 -07:00
Eric Traut
f306d366dd
Modified heuristics in T is None type narrowing logic to handle TypeVars with no bounds better. The previous logic was arguably correct, but it produced results that were unexpected by some users. This addresses #8575. (#8578) 2024-07-28 10:36:47 -07:00
Eric Traut
d3d24d35bd
Added convenience accessor functions for TypeVars to test for constra… (#8576)
* Added convenience accessor functions for TypeVars to test for constraints, bounds, and Self. No functional change.

* Fixed style issue
2024-07-28 09:01:30 -07:00
Eric Traut
7e8dfb76ad Added support for @deprecated on __new__ methods used implicitly during a class constructor call. This addresses #8574. 2024-07-28 08:11:38 -07:00
Eric Traut
513d2ea697
Added support for @deprecated on __bool__ magic method used by not operator. (#8573) 2024-07-27 23:17:23 -07:00
Eric Traut
ed679c69d3
Added support for @deprecated decorator on magic methods for unary and binary operations. (#8572) 2024-07-27 22:42:20 -07:00
Eric Traut
5d68698462
Fixed bug that results in a false negative if a __set__ descriptor method is marked deprecated and is implicitly accessed using an augmented assignment operator, as in a.x += 1. (#8571) 2024-07-27 21:57:49 -07:00
Eric Traut
3931155adb
Fixed recent regression that can lead to a crash. (#8570) 2024-07-27 21:49:13 -07:00
Eric Traut
28b5427d55 Renamed some concepts in the typeVarContext and constraintSolver modules in preparation for a larger change. 2024-07-27 15:44:03 -07:00
Eric Traut
5397ee3470 Removed import cycle in typeVarContext module. 2024-07-27 14:58:53 -07:00
Eric Traut
bffbc33b69 Cleaned up data structures for TypeVarType to provide better type protection for ParamSpec and TypeVarTuple fields. Renamed TypeVarTuple test cases to conform better to internal terminology.
(cherry picked from commit 0a15f335ec5bba5f1b0997ffec4c622dad74bf13)
2024-07-27 14:52:58 -07:00
Eric Traut
01a82e2023 Renamed some internal symbol names for brevity (parameter => param). No functional change. 2024-07-27 12:03:36 -07:00
Eric Traut
a74871d46f Simplified cloneForSpecialization call to improve brevity and readability. 2024-07-27 11:21:49 -07:00
Eric Traut
8cab57e657 Renamed some internal symbol names for brevity (argument => arg). No functional change. 2024-07-27 11:02:57 -07:00
Eric Traut
31df557056 Removed some unused functionality from the TypeVarContext. 2024-07-27 10:39:52 -07:00
Eric Traut
4b91a0b222 Moved type complexity calculation into its own module. 2024-07-27 10:31:13 -07:00
Eric Traut
2c4032a920 Simplified TypeVarContext by removing some of the special-case handling for tupleTypeArgs. 2024-07-27 10:20:33 -07:00
Eric Traut
2bbd1bf288
Fixed a bug that can result in incorrect type evaluation when an isinstance type narrowing results in an intersection type. (#8564) 2024-07-27 10:17:05 -07:00
Eric Traut
7e7ad07453
Removed special-casing for None that is no longer needed. (#8562) 2024-07-26 21:04:49 -07:00
Eric Traut
c385edf274
Added missing check for Final variable assigned in a loop. (#8561) 2024-07-26 17:08:24 -07:00
Eric Traut
5f145eb010
Fixed a bug that results in incorrect type narrowing when tuples are used in conjunction with TypeIs. This addresses #8554. (#8559) 2024-07-26 16:14:37 -07:00
Eric Traut
87609b7f43 Refactored some functionality out of the type evaluator into a new tuples.ts module. 2024-07-26 14:00:16 -07:00
Eric Traut
93ce674190 Refactored code that creates pseudo-intersection types for isinstance type narrowing. No functional change. 2024-07-26 13:22:13 -07:00
Eric Traut
b076b783cb
Fixed a bug that results in an incorrect "inconsistent overload" error when the overloads return TypeIs or TypeGuard and the implementation returns bool. This addresses #8521. (#8556) 2024-07-26 11:53:40 -07:00
Eric Traut
a1f24db683
Fixed recent regression that results in a false positive error under certain circumstances when yield expression includes a call to a constructor. This addresses #8552. (#8553) 2024-07-26 09:49:37 -07:00
Eric Traut
28b452ac0f Simplified previous commit. 2024-07-25 20:34:19 -07:00
Eric Traut
5cea702a7e
Enhanced type narrowing for sequence patterns to support tuple expansion when the subject is a tuple whose entries are union types. This addresses #8516, #4995, #6437, and #7472. (#8547) 2024-07-25 20:21:13 -07:00
Eric Traut
06d28c39d5
Added a new configuration option enableReachabilityAnalysis. It is off by default when typeCheckingMode is "off" but otherwise on by default. When disabled, it causes pyright not to identify code blocks that are determined to be unreachable via type analysis. Code blocks that are determined to be unreachable via non-type information are still displayed as such. (#8546) 2024-07-25 19:13:15 -07:00
Eric Traut
5dd321a280
Fixed false positive error when iterator returns a class object from its __iter__ method. (#8545) 2024-07-25 17:48:03 -07:00
Eric Traut
4c3def9bbc
Added error check for an enum attribute with a "naked" Final attribute. This should be considered invalid. This addresses #8543. (#8544) 2024-07-25 17:00:53 -07:00
Eric Traut
95be64edeb
Updated code flow engine to distinguish between code that is unreachable based on type information and non-type information. (#8541) 2024-07-25 14:38:32 -07:00
Heejae Chang
ee42447964
push pylance to pyright 2024.8 (#8540)
* push pylance to pyright 3

* change config change back

* dont run some tests in real venv
2024-07-25 13:38:32 -07:00
Eric Traut
033ca1909b
Removed a bunch of redundant code related to annotation evaluation. (#8538) 2024-07-25 12:14:19 -07:00
Eric Traut
00ca6c38e8
Eliminated error condition when using a subscript expression for a generic class that does not conform to type expression rules (e.g. list[1 + 2]) if the expression is a value expression. This addresses #8534. (#8537) 2024-07-25 11:07:48 -07:00
Eric Traut
8f9f679a26
Changed evaluation behavior for TypeVar bounds, constraints, and defaults to enforce type expression evaluation rules, consistent with the typing spec. (#8536) 2024-07-25 10:41:30 -07:00
Eric Traut
6750ce5d74
Fixed recent regression that results in a false positive error when evaluating certain nested constructor calls when used with bidirectional type inference. This addresses #8519. (#8535) 2024-07-25 08:59:40 -07:00
Eric Traut
d20a0a2644
Fixed bug that results in a warning if the self parameter in an __init__ method is given an explicit Self annotation. This addresses #8532. (#8533) 2024-07-25 07:55:56 -07:00
Eric Traut
785d21962a
Fixed recent regression that results in incorrect isinstance type narrowing when the filter class and the type are both protocols. This addresses #8518. (#8529) 2024-07-24 17:06:52 -07:00
Eric Traut
d602f22098 Improved signature help for constructor calls. Replaced old heuristics that displayed either the __init__ or __new__ signature with a mechanism that uses the recently-ratified typing spec algorithm for converting a constructor into a callable. This is prompted in part by [this discussion](https://discuss.python.org/t/copying-signature-of-init-to-a-mixin-class-method/58907/2). 2024-07-24 16:10:48 -07:00
Eric Traut
385c84cce3 Fixed a bug that results in a crash in certain conditions involving a corrupt builtins.pyi stub. This addresses #8509. 2024-07-24 13:06:52 -07:00
Eric Traut
2cbd8752b4
Fixed bug in isinstance type narrowing if the second argument is object and the first argument is a type instance. This addresses #8520. (#8527) 2024-07-24 13:05:39 -07:00
Eric Traut
d833078226 Fixed bug that results in a crash if Optional is used with no subscript (i.e. Optional[]). This addresses #8524. 2024-07-24 12:24:00 -07:00
Eric Traut
21bfd0f5bb
Fixed bug in logic that validates subtyping relationships between TypeIs[T], TypeGuard[T] and bool when used in a return type of a callable. This addresses #8521. (#8523) 2024-07-24 10:26:58 -07:00
Eric Traut
258e2754bd Published 1.1.373 2024-07-23 17:06:24 -07:00
Eric Traut
77684ec7fc
Added support for auto-synthesized __replace__ method in dataclass … (#8514)
* Added support for auto-synthesized `__replace__` method in dataclass and namedtuple classes, a new feature in Python 3.13. This addresses #8300.

* Fixed broken test on Linux due to file system case sensitivity.
2024-07-22 22:31:18 -07:00
Eric Traut
39757e4519
Updated typeshed stubs to the latest version. (#8512) 2024-07-22 20:57:57 -07:00
Eric Traut
408b20b6c5
Eliminated a fragile assumption that Sequence and MutableSequence are nominal classes rather than protocols. This assumption holds today, but it might not in the future, and the pattern matching logic shouldn't rely on it. (#8510) 2024-07-22 20:15:53 -07:00
Eric Traut
ea8188fc77 Fixed bug that results in a crash if an explicit specialization of a class parameterized by a ParamSpec has zero type arguments. This is a syntax error, but it shouldn't cause the type evaluator to crash. 2024-07-22 12:23:36 -07:00
Eric Traut
616b2a5eea
Added support for bidirectional type inference for __extra_types__ in a closed TypedDict. This addresses #8503. (#8507) 2024-07-22 07:14:40 -07:00
Eric Traut
b9d25687f4
Fixed issues with the reportInconsistentConstructor. It produced false negatives in some cases and produced bad error messages in other cases. This addresses #8501 and #8500. (#8502) 2024-07-21 00:06:36 -07:00
Eric Traut
e812172ecf
Removed redundant assignment flag. (#8499) 2024-07-20 19:17:47 -07:00
Eric Traut
79959e7f6f Shortened some internal names for readability. No functional change. 2024-07-20 18:49:21 -07:00
Eric Traut
c2a1d6a99a Made support for "converter" parameter in dataclass_transform fields non-experimental. This functionality has been approved by the typing council. 2024-07-19 22:37:48 -07:00
Eric Traut
bf4c521c67 Added test case for #8494, which was already fixed by a previous commit. 2024-07-19 20:20:12 -07:00
Eric Traut
7434085425
Simplified check of the __init__ method by leveraging common code. (#8495) 2024-07-19 20:14:14 -07:00
Eric Traut
3f4235e965 Removed recently-added finally because it gets in the way of debugging. 2024-07-19 13:08:55 -07:00
Eric Traut
a508fad80e
Fixed a bug that can cause a hang during type analysis for complex code with loops. There are rare circumstances that can cause types not to converge due to symbol dependencies and unstable overload resolution. This change adds a hard limit on the number of attempts to converge types in a loop before giving up. It addresses #8279. (#8491) 2024-07-19 11:28:54 -07:00
Eric Traut
3b5aba31df
Fixed bug that resulted in an infinite loop when evaluating a call that passes the same call as an argument. Simplified tracking of unique signatures within the code. This addresses #8047. (#8488) 2024-07-18 23:10:02 -07:00
Eric Traut
0eeffb0ab2
Improved type evaluation for tuples index expressions with negative subscripts and an entry with an indeterminate length. This addresses #8485. (#8486) 2024-07-18 19:22:37 -07:00
Eric Traut
7554fea844
Fixed bug that results in a false positive "overlapping overload" diagnostic when the later overload includes a callback function with a TypeVar in a parameter type. This addresses #8465. (#8484) 2024-07-18 19:18:28 -07:00
Eric Traut
405e6288cb
Fixed a bug that results in incorrect type narrowing when using TypeIs form when the return type of the type guard function is a specialized generic class. This addresses #8460. (#8483) 2024-07-18 16:35:10 -07:00
Eric Traut
55f1f5f6a8
Added the distinction between "external" versus "internal" type variable scopes. This is important for generic class implementations that call their own constructors. (#8482)
This is a significant change with high potential for regressions.

It addresses #8165, #7988, #7507, #7369.
2024-07-18 14:33:02 -07:00
Eric Traut
90b1bfbd34
Added check for class attribute type declarations that use method-bound type variables. These should be illegal. This addresses #8479. (#8480) 2024-07-18 12:17:45 -07:00
Eric Traut
20d985f007
Changed internal behavior to retain type alias information when applying solved type variables for a type. (#8476) 2024-07-18 09:38:50 -07:00
Eric Traut
f4ac69bf05
Added some additional improvements and tests from another working branch. (#8474) 2024-07-18 08:40:34 -07:00
Eric Traut
c6a449d1a1
Added a small optimization for the previous change to bidirectional inference for call expressions. (#8472) 2024-07-18 08:17:34 -07:00
Eric Traut
42c379bbb8 Added provisional support for draft PEP 736 (keyword argument shortcut syntax). This addresses #8470. 2024-07-18 01:13:42 -07:00
Eric Traut
1d9b8b5ece
Fixed a bug that results in a false positive error when using bidirectional type inference for a call expression where the expected type is a union. This addresses #8449 and #8463. (#8468) 2024-07-17 20:27:16 -07:00
Eric Traut
c116e6af19
Fixed a bug that results in incorrect type evaluation in certain edge cases involving bidirectional type inference with TypeVarTuples. (#8461) 2024-07-17 16:37:23 -07:00
Eric Traut
25cfdf7fcf
Changed all diagnostic generated in the type evaluator to have a diagnostic rule associated with them so their severity is under user control. This addresses #8453. (#8456) 2024-07-17 12:10:33 -07:00
Eric Traut
60c3b168a7
Fixed regression that results in a false positive when an Annotated type is used in a type argument within a specialized type on the LHS of a call expression, such as list[Annotated[int, ""]](). This addresses #8454. (#8455) 2024-07-17 11:57:56 -07:00
Eric Traut
d6372d4570 Published 1.1.372 2024-07-16 18:39:04 -07:00
Eric Traut
f5edd2b85d
Added some changes from another branch. (#8445)
Added some changes from another branch.
2024-07-16 12:50:25 -07:00
Eric Traut
5d6b96bc60
Incorporated several bug fixes and cleanups from an alternate branch. (#8443) 2024-07-16 11:13:20 -07:00
Eric Traut
e78b3b87f7
Refactored the code for TypeVar scope ID assignment to improve readability and maintenance. (#8440) 2024-07-15 16:47:10 -07:00
Eric Traut
baf6572b41
Fixed false positive error when using an overloaded __init_subclass__ method under certain circumstances. This addresses #8436. (#8439) 2024-07-15 15:08:26 -07:00
Eric Traut
b470f3e4d2
Changed logic for explicit specialization to allow Never as a type argument for a value-constrained type parameter if Never is an explicit constraint. This addresses #8432. (#8438) 2024-07-15 13:05:07 -07:00
Eric Traut
86869f0c94
Added "literal math" support for exponentiation operator. This addres… (#8437)
* Added "literal math" support for exponentiation operator. This addresses #8434.

* Refactored binary ops "literal math" code for maintainability and readability.
2024-07-15 12:49:45 -07:00
Eric Traut
042d2ea582
Fixed bug that results in some circumstances in incorrect specialization of type[T] when T evaluates to Any. This addresses #8429. (#8431) 2024-07-14 23:40:44 -07:00
Eric Traut
6990c98c12
Further simplified bidirectional inference logic for calls. (#8427) 2024-07-14 14:37:31 -07:00
Eric Traut
3bf626b020
Improved and simplified then handling constructor calls for classes t… (#8426)
* Improved and simplified then handling constructor calls for classes that have no `__init__` or `__new__` method.

* Removed unused localized string.
2024-07-14 11:34:56 -07:00
Eric Traut
89341d308d
Improved the handling of bidirectional type inference for call expressions when the expected type comprises a union. (#8425) 2024-07-14 11:07:16 -07:00
Eric Traut
b88e3dcef2
Incorporated some code cleanup changes from another working branch. (#8424) 2024-07-14 10:46:07 -07:00
Eric Traut
426fe55611
Fixed bug that results in a false positive error under certain circumstances when a generator function with no type annotation contains a return value. This addresses #8421. (#8422) 2024-07-14 09:01:52 -07:00
Eric Traut
9daf584ba4
Added "literal math" support for bitwise operators (left shift, right shift, logical or, logical and, logical xor, and invert). This addresses #8419. (#8420) 2024-07-13 23:09:16 -07:00
Eric Traut
f72be7b6b4 Added optimization to monomorphize objects used in the code flow engine. 2024-07-13 20:59:39 -07:00
Eric Traut
1e218a2cfe
Fixed inconsistent behavior when evaluating a binary expression with an or or and operator when the LHS evaluates to a literal int, str, bytes or bool type. This addresses #8417. (#8418) 2024-07-13 20:09:56 -07:00
Eric Traut
5192889fb5 Renamed fields in parse nodes to reduce verbosity and increase consistency. 2024-07-13 17:48:02 -07:00
Eric Traut
210bb144d7
Modified parser data structures to make parse nodes monomorphic and improve performance. (#8416) 2024-07-13 17:45:13 -07:00
Eric Traut
5ac7f49a3f Eliminated maxChildDepth field from parse nodes. 2024-07-13 15:55:32 -07:00
Eric Traut
496822d3d0
Modified typing data structures to increase monomorphism for performance reasons. (#8415) 2024-07-13 14:43:45 -07:00
Eric Traut
17bd81a7de
Next step in attempting to make typing types monomorphic. (#8413) 2024-07-13 12:35:34 -07:00
Eric Traut
d2d0fdcd23
Did a small refactor of the FunctionType interface and eliminated a field. (#8412) 2024-07-13 10:50:07 -07:00
Eric Traut
2f1bce7b25
Fixed a bug that results in incorrect import resolution behaviors when a ".py" file and a directory have the same name, and the directory doesn't have a __init__.py file in it. In this case, the ".py" file should take precedence during imports. This addresses #8408. (#8410) 2024-07-13 09:50:07 -07:00
Eric Traut
897081901e
Did some refactoring and code cleanup in import resolver in preparation for a bug fix. (#8409) 2024-07-13 09:27:41 -07:00
Eric Traut
47ea13bc2d
Changed the type of the __doc__ attribute for a module to always be str | None. Previously, pyright changed its declared type to str if a docstring was present in the module, but this is incorrect because it's a writable value and can be set to None. This addresses #8388. (#8397) 2024-07-12 10:58:20 -07:00
Eric Traut
96ee9c6268
Changed union creation logic to retain (rather than elide) redundant literals in some cases. In particular, for type expressions that explicitly include literals along with their non-literal counterpart like Literal[1] | int. Retaining these redundant subtypes can be useful for language server features like completion suggestions. This addresses #8392. (#8396) 2024-07-12 09:52:22 -07:00
Eric Traut
30e139b5f8
Fixed a bug that results in a false positive reportOverlappingOverload error in certain cases involving ParamSpec and Concatenate. This addresses #8389. (#8393) 2024-07-12 08:51:34 -07:00
Eric Traut
71928e1b00
Changed the way FunctionParam objects are created so they are monomorphic. (#8387) 2024-07-12 00:02:29 -07:00
Eric Traut
2f88f837d0
Did some code cleanup in the types module. Eliminated a few unnecessary optional fields in common objects. (#8386) 2024-07-11 21:51:36 -07:00
Eric Traut
a740945cd7 Removed the builtinName field from FunctionType. It can be represented by a flag more economically. 2024-07-11 20:49:26 -07:00
Eric Traut
2dffecb0f2
Added support for class declarations within an enum class body -- both with and without @member and @nonmember decorators. This addresses #8366. (#8385) 2024-07-11 20:31:19 -07:00
Eric Traut
827684ac2e
Fixed a bug that results in false positive reportInconsistentConstructor errors if one or both of __init__ or __new__ are overloaded. This addresses #8372. (#8383) 2024-07-11 19:27:25 -07:00
Eric Traut
39d76a86e7
Fixed a recent regression that results in a false positive when the fully-qualified form of typing.Request is used in an annotation expression. This addresses #8375. (#8381) 2024-07-11 17:36:23 -07:00
Eric Traut
472d86519d Improved consistency of parse node interface definitions. No functional change. 2024-07-11 16:56:22 -07:00
Rich Chiodo
d06b5999ca
Current working directory can't override OS so not necessary to remove it (#8364) 2024-07-10 10:49:42 -07:00
Eric Traut
109a9d03f8
Fixed bug in type narrowing logic for sequence pattern matching when a "star" entry in the pattern captures a TypeVarTuple. The resulting type should be Unknown rather than the unpacked TypeVarTuple. (#8365)
Fixed bug that results in a false positive when assigning type `tuple[Any, ...]` to `tuple[*TS]`. This should be allowed because `tuple[Any, ...]` is a gradual form that is assignable to all tuple types.

This addresses #8357.
2024-07-10 10:24:01 -07:00
Eric Traut
dded9fb056
Added support for negative type narrowing (in the fall-through case) for a mapping pattern consisting of a single dictionary expand entry. This should match all mapping types, eliminating them in the fall-through case. This addresses #8356. (#8363) 2024-07-10 09:27:47 -07:00
Eric Traut
4c4767ef81
Fixed bug that can result in incorrect evaluation of a traditional (pre-PEP 695) type alias the defines a union which is later used as the second argument to an isinstance or issubclass call. This addresses #8358. (#8362) 2024-07-10 08:19:14 -07:00
Eric Traut
8f82d8d3f6 Published 1.1.371 2024-07-09 15:29:04 -07:00
Rich Chiodo
d1b4d65616
Make python interpreter execution more secure (#8341)
* Make python interpreter execution more secure

* Fix test failure
2024-07-09 09:51:07 -07:00
Eric Traut
84b00a627d Updated lock file. 2024-07-08 23:02:54 -07:00
Eric Traut
9c16cc3e49 Bumped min engine version from 1.86 to 1.89 to match the recently-updated language client library requirements. This addresses #8344. 2024-07-08 23:01:35 -07:00
Eric Traut
1925023629 Fixed bug that causes a false positive error when an __init_subclass__ has overloads. This addresses #8343. 2024-07-08 22:59:40 -07:00
Eric Traut
f6dd5c5bef Updated typeshed stubs to the latest version. 2024-07-08 19:36:37 -07:00
Eric Traut
d785aac750
Fixed type evaluation of old-style (pre-PEP 695) type alias that aliases a generic class when it is used as a direct constructor call. This addresses #8337. (#8338) 2024-07-08 13:56:38 -07:00
Eric Traut
fd6081f12d
Did some general code cleanup in type evaluator including shortening names of some variables and functions for readability. (#8330) 2024-07-07 16:08:22 -07:00
Eric Traut
ab6fe409a6 Code cleanup for selfSpecializeClass. 2024-07-07 12:29:52 -07:00
Eric Traut
5332daa9cb Small code cleanup in validateCallForFunction. 2024-07-07 11:59:28 -07:00
Eric Traut
04490f2645 Reformatted test samples using ruff. 2024-07-07 10:34:25 -07:00
Eric Traut
7d410cfbee
Improved handling of tuple expressions used in type expressions that involve specialization, such as dict[()]. (#8329) 2024-07-07 10:06:08 -07:00