django-orm-lens 1.2.2__tar.gz → 1.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/PKG-INFO +1 -1
  2. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/parser.py +8 -3
  3. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/PKG-INFO +1 -1
  4. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/SOURCES.txt +1 -0
  5. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/pyproject.toml +1 -1
  6. django_orm_lens-1.2.3/tests/test_pep526_type_hints.py +97 -0
  7. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/README.md +0 -0
  8. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/__init__.py +0 -0
  9. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/cli.py +0 -0
  10. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/diff.py +0 -0
  11. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/formatters.py +0 -0
  12. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/mcp_server.py +0 -0
  13. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/migrations_parser.py +0 -0
  14. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/models.py +0 -0
  15. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/py.typed +0 -0
  16. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/query_analyzer.py +0 -0
  17. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens/signals_parser.py +0 -0
  18. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/dependency_links.txt +0 -0
  19. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/entry_points.txt +0 -0
  20. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/requires.txt +0 -0
  21. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/django_orm_lens.egg-info/top_level.txt +0 -0
  22. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/setup.cfg +0 -0
  23. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_abstract_and_auth_user.py +0 -0
  24. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_cli_hint.py +0 -0
  25. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_cli_subcommands_smoke.py +0 -0
  26. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_cli_verbose.py +0 -0
  27. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_cross_module_bases.py +0 -0
  28. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_diff_command.py +0 -0
  29. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_golden_fixtures.py +0 -0
  30. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_kwarg_order_and_auth_user.py +0 -0
  31. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_list_command.py +0 -0
  32. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_migration_risk.py +0 -0
  33. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_migrations_parser.py +0 -0
  34. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_nplusone_detector.py +0 -0
  35. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_parity.py +0 -0
  36. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_query_analyzer.py +0 -0
  37. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_scan_root.py +0 -0
  38. {django_orm_lens-1.2.2 → django_orm_lens-1.2.3}/tests/test_signals_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-orm-lens
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Static analysis + MCP server for Django models. Sidebar tree, ER diagrams, and JSON output for terminals and AI coding agents.
5
5
  Author: frowningdev
6
6
  License: MIT
@@ -121,16 +121,21 @@ def _build_body_regexes(indent: int):
121
121
  return cached
122
122
  w = r"\s{" + str(indent) + r"}"
123
123
  w2 = r"\s{" + str(indent * 2) + r"}"
124
+ # ``(?:\s*:[^=]+)?`` — optional PEP-526 type annotation between the field
125
+ # name and ``=``, e.g. ``jti: CharField[str] = models.CharField(...)``.
126
+ # ``[^=]+`` is safe because ``=`` never appears inside a type expression
127
+ # (subscripts, unions, dotted refs, and generics all use other punctuation).
128
+ ann = r"(?:\s*:[^=]+)?"
124
129
  result = {
125
130
  "FIELD_RE": re.compile(
126
- rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*models\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
131
+ rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*models\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
127
132
  ),
128
133
  "BARE_FIELD_RE": re.compile(
129
- rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*({BARE_FIELD_TYPES})\s*\("
134
+ rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*({BARE_FIELD_TYPES})\s*\("
130
135
  ),
131
136
  "META_START_RE": re.compile(rf"^{w}class\s+Meta\s*(?:\([^)]*\))?\s*:"),
132
137
  "META_ITEM_RE": re.compile(
133
- rf"^{w2}([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.+?)\s*(#.*)?$"
138
+ rf"^{w2}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*(.+?)\s*(#.*)?$"
134
139
  ),
135
140
  "META_BODY_RE": re.compile(r"^\s{" + str(indent * 2) + r",}"),
136
141
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-orm-lens
3
- Version: 1.2.2
3
+ Version: 1.2.3
4
4
  Summary: Static analysis + MCP server for Django models. Sidebar tree, ER diagrams, and JSON output for terminals and AI coding agents.
5
5
  Author: frowningdev
6
6
  License: MIT
@@ -30,6 +30,7 @@ tests/test_migration_risk.py
30
30
  tests/test_migrations_parser.py
31
31
  tests/test_nplusone_detector.py
32
32
  tests/test_parity.py
33
+ tests/test_pep526_type_hints.py
33
34
  tests/test_query_analyzer.py
34
35
  tests/test_scan_root.py
35
36
  tests/test_signals_parser.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "django-orm-lens"
7
- version = "1.2.2"
7
+ version = "1.2.3"
8
8
  description = "Static analysis + MCP server for Django models. Sidebar tree, ER diagrams, and JSON output for terminals and AI coding agents."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -0,0 +1,97 @@
1
+ """Regression test for issue #25 (jsabater):
2
+
3
+ Fields annotated with PEP-526 type hints — the modern Django Ninja / typed
4
+ Django style — used to disappear from the parsed model because the field
5
+ regex expected ``name = models.X(`` with no annotation between the name
6
+ and ``=``. When user code writes:
7
+
8
+ jti: CharField[str] = models.CharField(max_length=32, unique=True)
9
+
10
+ the pattern failed silently: no field parsed, sidebar tree empty, ER
11
+ diagram empty entity. Fixed by allowing an optional ``: <type>`` group
12
+ between the field name and the ``=`` in both ``FIELD_RE`` and
13
+ ``BARE_FIELD_RE`` (and ``META_ITEM_RE`` for consistency).
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import unittest
19
+
20
+ from django_orm_lens.parser import parse_models_file
21
+
22
+ SAMPLE = '''
23
+ from django.db import models
24
+ from django.db.models import CharField, IntegerField
25
+
26
+
27
+ class RevokedToken(models.Model):
28
+ """A revoked JWT, keyed by its jti claim (the token denylist)."""
29
+
30
+ # Exact snippet from the bug report — models.-prefixed with generic type hint.
31
+ jti: CharField[str] = models.CharField(max_length=32, unique=True)
32
+
33
+ # Bare import form + generic type hint.
34
+ revoked_count: IntegerField[int] = IntegerField(default=0)
35
+
36
+ # Simple annotation (no generic).
37
+ label: str = models.CharField(max_length=64)
38
+
39
+ # Backwards-compatible untyped form still works.
40
+ note = models.TextField(blank=True)
41
+ '''
42
+
43
+
44
+ class Pep526TypeAnnotationTest(unittest.TestCase):
45
+ def setUp(self) -> None:
46
+ self.models = parse_models_file("auth/models.py", SAMPLE)
47
+ self.assertEqual(len(self.models), 1, "RevokedToken class parsed")
48
+ self.token = self.models[0]
49
+
50
+ def test_all_four_fields_present(self) -> None:
51
+ names = [f.name for f in self.token.fields]
52
+ # The bug: type-hinted fields vanished, only untyped `note` survived.
53
+ self.assertEqual(names, ["jti", "revoked_count", "label", "note"])
54
+
55
+ def test_type_hinted_field_type_extracted(self) -> None:
56
+ # The field type comes from `models.CharField(...)`, not the annotation.
57
+ jti = next(f for f in self.token.fields if f.name == "jti")
58
+ self.assertEqual(jti.type, "CharField")
59
+
60
+ def test_bare_import_form_with_annotation(self) -> None:
61
+ rc = next(f for f in self.token.fields if f.name == "revoked_count")
62
+ self.assertEqual(rc.type, "IntegerField")
63
+
64
+ def test_simple_annotation(self) -> None:
65
+ label = next(f for f in self.token.fields if f.name == "label")
66
+ self.assertEqual(label.type, "CharField")
67
+
68
+ def test_untyped_form_still_works(self) -> None:
69
+ note = next(f for f in self.token.fields if f.name == "note")
70
+ self.assertEqual(note.type, "TextField")
71
+
72
+
73
+ META_SAMPLE = '''
74
+ from django.db import models
75
+
76
+
77
+ class Item(models.Model):
78
+ # Type-annotated field followed by Meta with type-annotated attribute.
79
+ title: str = models.CharField(max_length=100)
80
+
81
+ class Meta:
82
+ ordering: list[str] = ["title"]
83
+ '''
84
+
85
+
86
+ class Pep526MetaAnnotationTest(unittest.TestCase):
87
+ def test_meta_item_with_annotation(self) -> None:
88
+ models = parse_models_file("shop/models.py", META_SAMPLE)
89
+ item = models[0]
90
+ # The field itself must still be visible.
91
+ self.assertEqual([f.name for f in item.fields], ["title"])
92
+ # And the Meta annotation must not confuse the Meta reader.
93
+ self.assertEqual(item.meta.get("ordering"), '["title"]')
94
+
95
+
96
+ if __name__ == "__main__":
97
+ unittest.main()