mirror of https://github.com/astral-sh/ruff
[red-knot] add cycle handling for FunctionType::signature query
move some ecosystem projects from bad to good add mdtest
This commit is contained in:
parent
e95130ad80
commit
3bf77a9635
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Cycles
|
||||||
|
|
||||||
|
## Function signature
|
||||||
|
|
||||||
|
Deferred annotations can result in cycles in resolving a function signature:
|
||||||
|
|
||||||
|
```py
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
# error: [invalid-type-form]
|
||||||
|
def f(x: f):
|
||||||
|
pass
|
||||||
|
|
||||||
|
reveal_type(f) # revealed: def f(x: Unknown) -> Unknown
|
||||||
|
```
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
Expression # cycle panic (signature_)
|
|
||||||
Tanjun # cycle panic (signature_)
|
Tanjun # cycle panic (signature_)
|
||||||
altair # cycle panics (try_metaclass_)
|
altair # cycle panics (try_metaclass_)
|
||||||
antidote # hangs / slow
|
antidote # hangs / slow
|
||||||
|
|
@ -12,21 +11,16 @@ hydpy # cycle panics (try_metaclass_)
|
||||||
ibis # cycle panics (try_metaclass_)
|
ibis # cycle panics (try_metaclass_)
|
||||||
manticore # stack overflow
|
manticore # stack overflow
|
||||||
materialize # stack overflow
|
materialize # stack overflow
|
||||||
mypy # cycle panic (signature_)
|
|
||||||
pandas # slow
|
pandas # slow
|
||||||
pandas-stubs # cycle panics (try_metaclass_)
|
pandas-stubs # cycle panics (try_metaclass_)
|
||||||
pandera # cycle panics (try_metaclass_)
|
pandera # cycle panics (try_metaclass_)
|
||||||
prefect # slow
|
prefect # slow
|
||||||
pylint # cycle panics (self-recursive type alias)
|
pylint # cycle panics (self-recursive type alias)
|
||||||
pytest # cycle panics (signature_)
|
|
||||||
pywin32 # bad use-def map (binding with definitely-visible unbound)
|
pywin32 # bad use-def map (binding with definitely-visible unbound)
|
||||||
schemathesis # cycle panics (signature_)
|
|
||||||
scikit-learn # success, but mypy-primer hangs processing the output
|
scikit-learn # success, but mypy-primer hangs processing the output
|
||||||
scipy # missing expression type ("expression should belong to this TypeInference region")
|
scipy # missing expression type ("expression should belong to this TypeInference region")
|
||||||
spack # success, but mypy-primer hangs processing the output
|
spack # success, but mypy-primer hangs processing the output
|
||||||
spark # cycle panics (try_metaclass_)
|
spark # cycle panics (try_metaclass_)
|
||||||
steam.py # cycle panics (try_metaclass_), often hangs when multi-threaded
|
steam.py # cycle panics (try_metaclass_), often hangs when multi-threaded
|
||||||
streamlit # cycle panic (signature_)
|
|
||||||
sympy # stack overflow
|
sympy # stack overflow
|
||||||
trio # cycle panics (deferred annotatation resolving in wrong scope)
|
|
||||||
xarray # cycle panics (try_metaclass_)
|
xarray # cycle panics (try_metaclass_)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
AutoSplit
|
AutoSplit
|
||||||
|
Expression
|
||||||
PyGithub
|
PyGithub
|
||||||
PyWinCtl
|
PyWinCtl
|
||||||
SinbadCogs
|
SinbadCogs
|
||||||
|
|
@ -55,6 +56,7 @@ mkdocs
|
||||||
mkosi
|
mkosi
|
||||||
mongo-python-driver
|
mongo-python-driver
|
||||||
more-itertools
|
more-itertools
|
||||||
|
mypy
|
||||||
mypy-protobuf
|
mypy-protobuf
|
||||||
mypy_primer
|
mypy_primer
|
||||||
nionutils
|
nionutils
|
||||||
|
|
@ -82,6 +84,7 @@ pylox
|
||||||
pyodide
|
pyodide
|
||||||
pyp
|
pyp
|
||||||
pyppeteer
|
pyppeteer
|
||||||
|
pytest
|
||||||
pytest-robotframework
|
pytest-robotframework
|
||||||
python-chess
|
python-chess
|
||||||
python-htmlgen
|
python-htmlgen
|
||||||
|
|
@ -90,6 +93,7 @@ rclip
|
||||||
rich
|
rich
|
||||||
rotki
|
rotki
|
||||||
schema_salad
|
schema_salad
|
||||||
|
schemathesis
|
||||||
scrapy
|
scrapy
|
||||||
setuptools
|
setuptools
|
||||||
sockeye
|
sockeye
|
||||||
|
|
@ -99,7 +103,9 @@ starlette
|
||||||
static-frame
|
static-frame
|
||||||
stone
|
stone
|
||||||
strawberry
|
strawberry
|
||||||
|
streamlit
|
||||||
tornado
|
tornado
|
||||||
|
trio
|
||||||
twine
|
twine
|
||||||
typeshed-stats
|
typeshed-stats
|
||||||
urllib3
|
urllib3
|
||||||
|
|
|
||||||
|
|
@ -6495,6 +6495,11 @@ impl<'db> FunctionSignature<'db> {
|
||||||
pub(crate) fn iter(&self) -> Iter<Signature<'db>> {
|
pub(crate) fn iter(&self) -> Iter<Signature<'db>> {
|
||||||
self.as_slice().iter()
|
self.as_slice().iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the "bottom" signature (subtype of all fully-static signatures.)
|
||||||
|
pub(crate) fn bottom(db: &'db dyn Db) -> Self {
|
||||||
|
Self::Single(Signature::bottom(db))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> IntoIterator for &'db FunctionSignature<'db> {
|
impl<'db> IntoIterator for &'db FunctionSignature<'db> {
|
||||||
|
|
@ -6639,7 +6644,7 @@ impl<'db> FunctionType<'db> {
|
||||||
///
|
///
|
||||||
/// Were this not a salsa query, then the calling query
|
/// Were this not a salsa query, then the calling query
|
||||||
/// would depend on the function's AST and rerun for every change in that file.
|
/// would depend on the function's AST and rerun for every change in that file.
|
||||||
#[salsa::tracked(return_ref)]
|
#[salsa::tracked(return_ref, cycle_fn=signature_cycle_recover, cycle_initial=signature_cycle_initial)]
|
||||||
pub(crate) fn signature(self, db: &'db dyn Db) -> FunctionSignature<'db> {
|
pub(crate) fn signature(self, db: &'db dyn Db) -> FunctionSignature<'db> {
|
||||||
if let Some(overloaded) = self.to_overloaded(db) {
|
if let Some(overloaded) = self.to_overloaded(db) {
|
||||||
FunctionSignature::Overloaded(
|
FunctionSignature::Overloaded(
|
||||||
|
|
@ -6849,6 +6854,22 @@ impl<'db> FunctionType<'db> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn signature_cycle_recover<'db>(
|
||||||
|
_db: &'db dyn Db,
|
||||||
|
_value: &FunctionSignature<'db>,
|
||||||
|
_count: u32,
|
||||||
|
_function: FunctionType<'db>,
|
||||||
|
) -> salsa::CycleRecoveryAction<FunctionSignature<'db>> {
|
||||||
|
salsa::CycleRecoveryAction::Iterate
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature_cycle_initial<'db>(
|
||||||
|
db: &'db dyn Db,
|
||||||
|
_function: FunctionType<'db>,
|
||||||
|
) -> FunctionSignature<'db> {
|
||||||
|
FunctionSignature::bottom(db)
|
||||||
|
}
|
||||||
|
|
||||||
/// Non-exhaustive enumeration of known functions (e.g. `builtins.reveal_type`, ...) that might
|
/// Non-exhaustive enumeration of known functions (e.g. `builtins.reveal_type`, ...) that might
|
||||||
/// have special behavior.
|
/// have special behavior.
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,16 @@ impl<'db> Signature<'db> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the "bottom" signature, subtype of all other fully-static signatures.
|
||||||
|
pub(crate) fn bottom(db: &'db dyn Db) -> Self {
|
||||||
|
Self {
|
||||||
|
generic_context: None,
|
||||||
|
inherited_generic_context: None,
|
||||||
|
parameters: Parameters::object(db),
|
||||||
|
return_ty: Some(Type::Never),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn normalized(&self, db: &'db dyn Db) -> Self {
|
pub(crate) fn normalized(&self, db: &'db dyn Db) -> Self {
|
||||||
Self {
|
Self {
|
||||||
generic_context: self.generic_context,
|
generic_context: self.generic_context,
|
||||||
|
|
@ -957,7 +967,6 @@ impl<'db> Parameters<'db> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return parameters that represents `(*args: object, **kwargs: object)`.
|
/// Return parameters that represents `(*args: object, **kwargs: object)`.
|
||||||
#[cfg(test)]
|
|
||||||
pub(crate) fn object(db: &'db dyn Db) -> Self {
|
pub(crate) fn object(db: &'db dyn Db) -> Self {
|
||||||
Self {
|
Self {
|
||||||
value: vec![
|
value: vec![
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue