mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
fix @output decorator
This commit is contained in:
@@ -127,7 +127,7 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str]) -> None:
|
|||||||
actual = _clean_up(actual)
|
actual = _clean_up(actual)
|
||||||
error_message = ''
|
error_message = ''
|
||||||
|
|
||||||
if actual != expected:
|
if set(actual) != set(expected):
|
||||||
num_skip_start = _num_skipped_prefix_lines(expected, actual)
|
num_skip_start = _num_skipped_prefix_lines(expected, actual)
|
||||||
num_skip_end = _num_skipped_suffix_lines(expected, actual)
|
num_skip_end = _num_skipped_suffix_lines(expected, actual)
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def reveal_type(obj: Any) -> None:
|
|||||||
|
|
||||||
def output(output_lines: str):
|
def output(output_lines: str):
|
||||||
def decor(func: Callable[..., None]):
|
def decor(func: Callable[..., None]):
|
||||||
func.out = output_lines
|
func.out = output_lines.strip()
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
@@ -123,7 +123,7 @@ def fname_to_module(fpath: Path, root_path: Path) -> Optional[str]:
|
|||||||
|
|
||||||
|
|
||||||
class MypyTypecheckItem(pytest.Item):
|
class MypyTypecheckItem(pytest.Item):
|
||||||
root_directory = '/run/testdata'
|
root_directory = '/tmp'
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
@@ -255,7 +255,8 @@ def extract_test_output(attr: Callable[..., None]) -> List[str]:
|
|||||||
out_data: str = getattr(attr, 'out', None)
|
out_data: str = getattr(attr, 'out', None)
|
||||||
out_lines = []
|
out_lines = []
|
||||||
if out_data:
|
if out_data:
|
||||||
for line in out_data.split('\n'):
|
for line in out_data.strip().split('\n'):
|
||||||
|
if line:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
out_lines.append(line)
|
out_lines.append(line)
|
||||||
return out_lines
|
return out_lines
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from test.pytest_plugin import reveal_type
|
from test.pytest_plugin import reveal_type, output
|
||||||
from test.pytest_tests.base import BaseDjangoPluginTestCase
|
from test.pytest_tests.base import BaseDjangoPluginTestCase
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +48,20 @@ class TestForeignKey(BaseDjangoPluginTestCase):
|
|||||||
publisher = Publisher()
|
publisher = Publisher()
|
||||||
reveal_type(publisher.books) # E: Revealed type is 'django.db.models.query.QuerySet[main.Book]'
|
reveal_type(publisher.books) # E: Revealed type is 'django.db.models.query.QuerySet[main.Book]'
|
||||||
|
|
||||||
|
@output(
|
||||||
|
"""
|
||||||
|
main:4: warning: to= parameter type Instance is not supported
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
def test_to_parameter_as_string_fallbacks_to_any(self):
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
class Book(models.Model):
|
||||||
|
publisher = models.ForeignKey(to='Publisher', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
book = Book()
|
||||||
|
reveal_type(book.publisher) # E: Revealed type is 'Any'
|
||||||
|
|
||||||
|
|
||||||
class TestOneToOneField(BaseDjangoPluginTestCase):
|
class TestOneToOneField(BaseDjangoPluginTestCase):
|
||||||
def test_onetoone_field(self):
|
def test_onetoone_field(self):
|
||||||
|
|||||||
@@ -10,19 +10,4 @@ class TestObjectsQueryset(BaseDjangoPluginTestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
reveal_type(User.objects) # E: Revealed type is 'django.db.models.query.QuerySet[main.User]'
|
reveal_type(User.objects) # E: Revealed type is 'django.db.models.query.QuerySet[main.User]'
|
||||||
|
|
||||||
@output("""
|
|
||||||
main:10: error: Revealed type is 'Any'
|
|
||||||
main:10: error: "Type[ModelMixin]" has no attribute "objects"
|
|
||||||
""")
|
|
||||||
def test_objects_get_returns_model_instance(self):
|
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
class ModelMixin(models.Model):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
class User(ModelMixin):
|
|
||||||
pass
|
|
||||||
|
|
||||||
reveal_type(User.objects.get()) # E: Revealed type is 'main.User*'
|
reveal_type(User.objects.get()) # E: Revealed type is 'main.User*'
|
||||||
|
|||||||
Reference in New Issue
Block a user