deproc-python 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
- deproc/plugins/python/__init__.py +11 -1
- deproc/plugins/python/resolver/__init__.py +13 -1
- deproc/plugins/python/resolver/main.py +332 -72
- deproc/plugins/python/resolver/models.py +54 -1
- deproc/plugins/python/utils/exports.py +15 -6
- deproc/plugins/python/utils/mro.py +18 -0
- deproc/plugins/python/utils/serialization.py +9 -0
- {deproc_python-0.2.0.dist-info → deproc_python-0.2.1.dist-info}/METADATA +1 -1
- {deproc_python-0.2.0.dist-info → deproc_python-0.2.1.dist-info}/RECORD +11 -11
- {deproc_python-0.2.0.dist-info → deproc_python-0.2.1.dist-info}/WHEEL +0 -0
- {deproc_python-0.2.0.dist-info → deproc_python-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
from .linker import PythonLinker
|
|
2
2
|
from .parser import PythonSourceParser
|
|
3
|
-
from .resolver import
|
|
3
|
+
from .resolver import (
|
|
4
|
+
PythonBaseResolution,
|
|
5
|
+
PythonClassMROResult,
|
|
6
|
+
PythonInheritedMember,
|
|
7
|
+
PythonInheritedMembersResult,
|
|
8
|
+
PythonResolver,
|
|
9
|
+
)
|
|
4
10
|
from .symbol_cache import PythonSymbolCache
|
|
5
11
|
|
|
6
12
|
__all__ = [
|
|
13
|
+
"PythonBaseResolution",
|
|
14
|
+
"PythonClassMROResult",
|
|
15
|
+
"PythonInheritedMember",
|
|
16
|
+
"PythonInheritedMembersResult",
|
|
7
17
|
"PythonLinker",
|
|
8
18
|
"PythonResolver",
|
|
9
19
|
"PythonSourceParser",
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
from .main import PythonResolver
|
|
2
|
+
from .models import (
|
|
3
|
+
PythonBaseResolution,
|
|
4
|
+
PythonClassMROResult,
|
|
5
|
+
PythonInheritedMember,
|
|
6
|
+
PythonInheritedMembersResult,
|
|
7
|
+
)
|
|
2
8
|
|
|
3
|
-
__all__ = [
|
|
9
|
+
__all__ = [
|
|
10
|
+
"PythonBaseResolution",
|
|
11
|
+
"PythonClassMROResult",
|
|
12
|
+
"PythonInheritedMember",
|
|
13
|
+
"PythonInheritedMembersResult",
|
|
14
|
+
"PythonResolver",
|
|
15
|
+
]
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
from collections.abc import Mapping
|
|
2
3
|
|
|
3
4
|
from deproc.core.context import Context
|
|
4
5
|
from deproc.core.interfaces.parser.models import Entity
|
|
5
|
-
from deproc.core.interfaces.resolver import Resolver
|
|
6
|
+
from deproc.core.interfaces.resolver import ResolutionStatus, Resolver
|
|
6
7
|
|
|
7
8
|
from ..parser.models import (
|
|
8
9
|
PythonClass,
|
|
@@ -13,8 +14,12 @@ from ..parser.models import (
|
|
|
13
14
|
)
|
|
14
15
|
from ..utils.exports import build_module_exports, get_dynamic_export_modules
|
|
15
16
|
from ..utils.imports import resolve_relative_import_path
|
|
16
|
-
from ..utils.mro import
|
|
17
|
+
from ..utils.mro import compute_mro_from_base_ids
|
|
17
18
|
from .models import (
|
|
19
|
+
PythonBaseResolution,
|
|
20
|
+
PythonClassMROResult,
|
|
21
|
+
PythonInheritedMember,
|
|
22
|
+
PythonInheritedMembersResult,
|
|
18
23
|
PythonResolverResult,
|
|
19
24
|
ResolvedIDs,
|
|
20
25
|
UnresolvedIDs,
|
|
@@ -318,100 +323,345 @@ class PythonResolver(Resolver[PythonResolverResult]):
|
|
|
318
323
|
)
|
|
319
324
|
return resolved_ids, unresolved_ids
|
|
320
325
|
|
|
321
|
-
def
|
|
326
|
+
def resolve_import_alias(
|
|
327
|
+
self, alias_id: SymbolID, context: Context
|
|
328
|
+
) -> PythonResolverResult:
|
|
329
|
+
"""Resolve one imported binding without reinterpreting its import syntax."""
|
|
330
|
+
alias = self._get_symbol(alias_id, context)
|
|
331
|
+
if not isinstance(alias, PythonImportAlias):
|
|
332
|
+
return PythonResolverResult(
|
|
333
|
+
resolved_ids=set(),
|
|
334
|
+
unresolved_ids={alias_id},
|
|
335
|
+
reason=f"entity {alias_id} is not a Python import alias",
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
resolved_ids, unresolved_ids = self.resolve_alias_ids({alias_id}, context)
|
|
339
|
+
ambiguous_ids = resolved_ids if len(resolved_ids) > 1 else set()
|
|
340
|
+
if ambiguous_ids:
|
|
341
|
+
reason = f"Multiple symbols found for imported binding '{alias.name}'"
|
|
342
|
+
elif not resolved_ids:
|
|
343
|
+
reason = f"No symbol found for imported binding '{alias.name}'"
|
|
344
|
+
else:
|
|
345
|
+
reason = None
|
|
346
|
+
return PythonResolverResult(
|
|
347
|
+
resolved_ids=resolved_ids,
|
|
348
|
+
unresolved_ids=unresolved_ids,
|
|
349
|
+
ambiguous_ids=ambiguous_ids,
|
|
350
|
+
reason=reason,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
@staticmethod
|
|
354
|
+
def _normalize_base_name(base_name: str) -> str:
|
|
355
|
+
return base_name.split("[", 1)[0].strip()
|
|
356
|
+
|
|
357
|
+
def _resolve_qualified_base_name(
|
|
358
|
+
self,
|
|
359
|
+
cls: PythonClass,
|
|
360
|
+
qualified_name: str,
|
|
361
|
+
context: Context,
|
|
362
|
+
) -> tuple[ResolvedIDs, UnresolvedIDs]:
|
|
322
363
|
module = self._get_module(cls.id, context)
|
|
323
364
|
if module is None:
|
|
324
|
-
return
|
|
365
|
+
return set(), set()
|
|
325
366
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
367
|
+
components = qualified_name.split(".")
|
|
368
|
+
resolved_ids, unresolved_ids = self.resolve_symbol(
|
|
369
|
+
module.fqn, components[0], context
|
|
370
|
+
)
|
|
371
|
+
binding_prefix_length = 1
|
|
372
|
+
for binding_id in self.get_ids_by_fqn(module.fqn, components[0], context):
|
|
373
|
+
binding = self._get_symbol(binding_id, context)
|
|
374
|
+
if not isinstance(binding, PythonImportAlias) or binding.alias is not None:
|
|
375
|
+
continue
|
|
376
|
+
if binding.parent_id is None:
|
|
377
|
+
continue
|
|
378
|
+
import_statement = self._get_symbol(binding.parent_id, context)
|
|
379
|
+
if not isinstance(import_statement, PythonImportStatement):
|
|
380
|
+
continue
|
|
381
|
+
if import_statement.type != "generic_import":
|
|
382
|
+
continue
|
|
383
|
+
target_fqn = binding.import_path or self._get_target_module_fqn(
|
|
384
|
+
import_statement.id, context
|
|
385
|
+
)
|
|
386
|
+
if not target_fqn:
|
|
330
387
|
continue
|
|
331
|
-
|
|
388
|
+
target_components = target_fqn.split(".")
|
|
389
|
+
if components[: len(target_components)] == target_components:
|
|
390
|
+
binding_prefix_length = max(
|
|
391
|
+
binding_prefix_length, len(target_components)
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
for component in components[binding_prefix_length:]:
|
|
395
|
+
next_resolved_ids: ResolvedIDs = set()
|
|
396
|
+
next_unresolved_ids: UnresolvedIDs = set(unresolved_ids)
|
|
397
|
+
for container_id in resolved_ids:
|
|
398
|
+
container = self._get_symbol(container_id, context)
|
|
399
|
+
container_fqn = getattr(container, "fqn", None)
|
|
400
|
+
if not container_fqn:
|
|
401
|
+
continue
|
|
402
|
+
resolved, unresolved = self.resolve_symbol(
|
|
403
|
+
container_fqn, component, context
|
|
404
|
+
)
|
|
405
|
+
next_resolved_ids.update(resolved)
|
|
406
|
+
next_unresolved_ids.update(unresolved)
|
|
407
|
+
resolved_ids = next_resolved_ids
|
|
408
|
+
unresolved_ids = next_unresolved_ids
|
|
332
409
|
if not resolved_ids:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
410
|
+
break
|
|
411
|
+
|
|
412
|
+
return resolved_ids, unresolved_ids
|
|
413
|
+
|
|
414
|
+
def _resolve_base(
|
|
415
|
+
self,
|
|
416
|
+
cls: PythonClass,
|
|
417
|
+
base_name: str,
|
|
418
|
+
context: Context,
|
|
419
|
+
base_overrides: Mapping[tuple[SymbolID, str], SymbolID] | None = None,
|
|
420
|
+
) -> PythonBaseResolution:
|
|
421
|
+
normalized_name = self._normalize_base_name(base_name)
|
|
422
|
+
override_id = (base_overrides or {}).get((cls.id, normalized_name))
|
|
423
|
+
if override_id:
|
|
424
|
+
override = self._get_symbol(override_id, context)
|
|
425
|
+
if isinstance(override, PythonClass):
|
|
426
|
+
return PythonBaseResolution(
|
|
427
|
+
name=base_name,
|
|
428
|
+
status=ResolutionStatus.RESOLVED,
|
|
429
|
+
resolved_id=override_id,
|
|
430
|
+
candidates=(override_id,),
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
unresolved_ids: set[SymbolID] = set()
|
|
434
|
+
if "." in normalized_name:
|
|
435
|
+
resolved_ids, unresolved_ids = self._resolve_qualified_base_name(
|
|
436
|
+
cls, normalized_name, context
|
|
437
|
+
)
|
|
438
|
+
else:
|
|
439
|
+
resolved_ids = context.entity_registry.get_ids_by_fqn(normalized_name)
|
|
440
|
+
if not resolved_ids:
|
|
441
|
+
module = self._get_module(cls.id, context)
|
|
442
|
+
if module is None:
|
|
443
|
+
return PythonBaseResolution(
|
|
444
|
+
name=base_name,
|
|
445
|
+
status=ResolutionStatus.UNRESOLVED,
|
|
446
|
+
reason=f"containing module not found for base {base_name}",
|
|
341
447
|
)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return base_ids
|
|
448
|
+
resolved_ids, unresolved_ids = self.resolve_symbol(
|
|
449
|
+
module.fqn, normalized_name, context
|
|
450
|
+
)
|
|
346
451
|
|
|
347
|
-
|
|
452
|
+
class_ids = tuple(
|
|
453
|
+
sorted(
|
|
454
|
+
symbol_id
|
|
455
|
+
for symbol_id in resolved_ids
|
|
456
|
+
if isinstance(self._get_symbol(symbol_id, context), PythonClass)
|
|
457
|
+
)
|
|
458
|
+
)
|
|
459
|
+
if len(class_ids) == 1:
|
|
460
|
+
return PythonBaseResolution(
|
|
461
|
+
name=base_name,
|
|
462
|
+
status=ResolutionStatus.RESOLVED,
|
|
463
|
+
resolved_id=class_ids[0],
|
|
464
|
+
candidates=class_ids,
|
|
465
|
+
)
|
|
466
|
+
if len(class_ids) > 1:
|
|
467
|
+
return PythonBaseResolution(
|
|
468
|
+
name=base_name,
|
|
469
|
+
status=ResolutionStatus.AMBIGUOUS,
|
|
470
|
+
candidates=class_ids,
|
|
471
|
+
reason=f"ambiguous Python base {base_name}",
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
reason = f"Python base {base_name} was not resolved"
|
|
475
|
+
if unresolved_ids:
|
|
476
|
+
reason = f"Python base {base_name} has unresolved import candidates"
|
|
477
|
+
return PythonBaseResolution(
|
|
478
|
+
name=base_name,
|
|
479
|
+
status=ResolutionStatus.UNRESOLVED,
|
|
480
|
+
reason=reason,
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
def _resolve_base_resolutions(
|
|
484
|
+
self,
|
|
485
|
+
cls: PythonClass,
|
|
486
|
+
context: Context,
|
|
487
|
+
base_overrides: Mapping[tuple[SymbolID, str], SymbolID] | None = None,
|
|
488
|
+
) -> tuple[PythonBaseResolution, ...]:
|
|
489
|
+
return tuple(
|
|
490
|
+
self._resolve_base(cls, base_name, context, base_overrides)
|
|
491
|
+
for base_name in cls.inherits
|
|
492
|
+
if self._normalize_base_name(base_name)
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
def resolve_class_mro(
|
|
348
496
|
self,
|
|
349
497
|
class_id: SymbolID,
|
|
350
498
|
context: Context,
|
|
351
|
-
|
|
499
|
+
base_overrides: Mapping[tuple[SymbolID, str], SymbolID] | None = None,
|
|
500
|
+
) -> PythonClassMROResult:
|
|
501
|
+
return self._resolve_class_mro(
|
|
502
|
+
class_id, context, {}, set(), base_overrides or {}
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
def _resolve_class_mro(
|
|
506
|
+
self,
|
|
507
|
+
class_id: SymbolID,
|
|
508
|
+
context: Context,
|
|
509
|
+
memo: dict[SymbolID, PythonClassMROResult],
|
|
352
510
|
active: set[SymbolID],
|
|
353
|
-
|
|
511
|
+
base_overrides: Mapping[tuple[SymbolID, str], SymbolID],
|
|
512
|
+
) -> PythonClassMROResult:
|
|
354
513
|
if class_id in memo:
|
|
355
514
|
return memo[class_id]
|
|
356
515
|
if class_id in active:
|
|
357
|
-
return
|
|
516
|
+
return PythonClassMROResult(
|
|
517
|
+
status=ResolutionStatus.UNRESOLVED,
|
|
518
|
+
mro_ids=(class_id,),
|
|
519
|
+
reason="cyclic Python inheritance",
|
|
520
|
+
)
|
|
358
521
|
|
|
359
522
|
cls = self._get_symbol(class_id, context)
|
|
360
523
|
if not isinstance(cls, PythonClass):
|
|
361
|
-
|
|
362
|
-
|
|
524
|
+
return PythonClassMROResult(
|
|
525
|
+
status=ResolutionStatus.UNRESOLVED,
|
|
526
|
+
reason=f"entity {class_id} is not a Python class",
|
|
527
|
+
)
|
|
528
|
+
|
|
363
529
|
active.add(class_id)
|
|
364
|
-
|
|
365
|
-
if
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
530
|
+
bases = self._resolve_base_resolutions(cls, context, base_overrides)
|
|
531
|
+
if not bases:
|
|
532
|
+
result = PythonClassMROResult(
|
|
533
|
+
status=ResolutionStatus.RESOLVED,
|
|
534
|
+
mro_ids=(class_id,),
|
|
535
|
+
)
|
|
536
|
+
memo[class_id] = result
|
|
370
537
|
active.remove(class_id)
|
|
371
|
-
|
|
372
|
-
return memo[class_id]
|
|
538
|
+
return result
|
|
373
539
|
|
|
374
|
-
base_mros:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
540
|
+
base_mros: list[list[SymbolID] | None] = []
|
|
541
|
+
base_ids: list[SymbolID] = []
|
|
542
|
+
failure_status: ResolutionStatus | None = None
|
|
543
|
+
failure_reason: str | None = None
|
|
544
|
+
|
|
545
|
+
for base in bases:
|
|
546
|
+
if base.status is not ResolutionStatus.RESOLVED or base.resolved_id is None:
|
|
547
|
+
failure_status = base.status
|
|
548
|
+
failure_reason = base.reason
|
|
549
|
+
break
|
|
550
|
+
|
|
551
|
+
base_result = self._resolve_class_mro(
|
|
552
|
+
base.resolved_id,
|
|
553
|
+
context,
|
|
554
|
+
memo,
|
|
555
|
+
active,
|
|
556
|
+
base_overrides,
|
|
557
|
+
)
|
|
558
|
+
if not base_result.mro_ids:
|
|
559
|
+
failure_status = ResolutionStatus.UNRESOLVED
|
|
560
|
+
failure_reason = f"no MRO available for base {base.name}"
|
|
561
|
+
break
|
|
562
|
+
base_mros.append(list(base_result.mro_ids))
|
|
563
|
+
base_ids.append(base.resolved_id)
|
|
564
|
+
if base_result.status is not ResolutionStatus.RESOLVED:
|
|
565
|
+
failure_status = base_result.status
|
|
566
|
+
failure_reason = base_result.reason
|
|
567
|
+
break
|
|
568
|
+
|
|
569
|
+
mro_ids = compute_mro_from_base_ids(class_id, base_mros, base_ids)
|
|
570
|
+
if mro_ids is not None and class_id in mro_ids[1:]:
|
|
571
|
+
mro_ids = [class_id, *[mro_id for mro_id in mro_ids if mro_id != class_id]]
|
|
572
|
+
failure_status = failure_status or ResolutionStatus.UNRESOLVED
|
|
573
|
+
failure_reason = failure_reason or "cyclic Python inheritance"
|
|
574
|
+
|
|
575
|
+
if mro_ids is None:
|
|
576
|
+
result = PythonClassMROResult(
|
|
577
|
+
status=failure_status or ResolutionStatus.UNRESOLVED,
|
|
578
|
+
mro_ids=(class_id,),
|
|
579
|
+
bases=bases,
|
|
580
|
+
reason=failure_reason or f"inconsistent MRO for {cls.fqn}",
|
|
581
|
+
)
|
|
582
|
+
else:
|
|
583
|
+
result = PythonClassMROResult(
|
|
584
|
+
status=failure_status or ResolutionStatus.RESOLVED,
|
|
585
|
+
mro_ids=tuple(mro_ids),
|
|
586
|
+
bases=bases,
|
|
587
|
+
reason=failure_reason,
|
|
588
|
+
)
|
|
391
589
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
590
|
+
memo[class_id] = result
|
|
591
|
+
active.remove(class_id)
|
|
592
|
+
return result
|
|
593
|
+
|
|
594
|
+
def get_inherited_members(
|
|
595
|
+
self,
|
|
596
|
+
class_id: SymbolID,
|
|
597
|
+
context: Context,
|
|
598
|
+
mro_result: PythonClassMROResult | None = None,
|
|
599
|
+
) -> PythonInheritedMembersResult:
|
|
600
|
+
result = mro_result or self.resolve_class_mro(class_id, context)
|
|
601
|
+
if not result.mro_ids:
|
|
602
|
+
return PythonInheritedMembersResult(
|
|
603
|
+
status=result.status,
|
|
604
|
+
reason=result.reason,
|
|
605
|
+
)
|
|
397
606
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
607
|
+
cls = self._get_symbol(class_id, context)
|
|
608
|
+
if not isinstance(cls, PythonClass):
|
|
609
|
+
return PythonInheritedMembersResult(
|
|
610
|
+
status=ResolutionStatus.UNRESOLVED,
|
|
611
|
+
mro_ids=result.mro_ids,
|
|
612
|
+
reason=f"entity {class_id} is not a Python class",
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
own_ids = [*cls.method_ids, *cls.property_ids, *cls.inner_type_ids]
|
|
616
|
+
seen_names = {
|
|
617
|
+
getattr(self._get_symbol(member_id, context), "name", "")
|
|
618
|
+
for member_id in own_ids
|
|
619
|
+
}
|
|
620
|
+
members: list[PythonInheritedMember] = []
|
|
621
|
+
for depth, owner_id in enumerate(result.mro_ids[1:], 1):
|
|
622
|
+
owner = self._get_symbol(owner_id, context)
|
|
623
|
+
if not isinstance(owner, PythonClass):
|
|
402
624
|
continue
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
625
|
+
member_ids = [
|
|
626
|
+
*owner.method_ids,
|
|
627
|
+
*owner.property_ids,
|
|
628
|
+
*owner.inner_type_ids,
|
|
407
629
|
]
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
630
|
+
for member_id in member_ids:
|
|
631
|
+
member = self._get_symbol(member_id, context)
|
|
632
|
+
name = getattr(member, "name", "") if member else ""
|
|
633
|
+
if not name or name in seen_names:
|
|
634
|
+
continue
|
|
635
|
+
seen_names.add(name)
|
|
636
|
+
members.append(
|
|
637
|
+
PythonInheritedMember(
|
|
638
|
+
member_id=member_id,
|
|
639
|
+
owner_id=owner_id,
|
|
640
|
+
name=name,
|
|
641
|
+
mro_depth=depth,
|
|
642
|
+
)
|
|
643
|
+
)
|
|
413
644
|
|
|
414
|
-
|
|
645
|
+
return PythonInheritedMembersResult(
|
|
646
|
+
status=result.status,
|
|
647
|
+
mro_ids=result.mro_ids,
|
|
648
|
+
members=tuple(members),
|
|
649
|
+
reason=result.reason,
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
def _class_mro_ids(
|
|
653
|
+
self,
|
|
654
|
+
class_id: SymbolID,
|
|
655
|
+
context: Context,
|
|
656
|
+
memo: dict[SymbolID, list[SymbolID] | None],
|
|
657
|
+
active: set[SymbolID],
|
|
658
|
+
) -> list[SymbolID] | None:
|
|
659
|
+
if class_id in memo:
|
|
660
|
+
return memo[class_id]
|
|
661
|
+
result = self.resolve_class_mro(class_id, context)
|
|
662
|
+
mro_ids = (
|
|
663
|
+
list(result.mro_ids) if result.status is ResolutionStatus.RESOLVED else None
|
|
664
|
+
)
|
|
415
665
|
memo[class_id] = mro_ids
|
|
416
666
|
return mro_ids
|
|
417
667
|
|
|
@@ -421,6 +671,16 @@ class PythonResolver(Resolver[PythonResolverResult]):
|
|
|
421
671
|
resolved_ids, unresolved_ids = self.resolve_symbol(
|
|
422
672
|
module_fqn, symbol_name, context
|
|
423
673
|
)
|
|
674
|
+
ambiguous_ids = resolved_ids if len(resolved_ids) > 1 else set()
|
|
675
|
+
if ambiguous_ids:
|
|
676
|
+
reason = f"Multiple symbols found for '{module_fqn}.{symbol_name}'"
|
|
677
|
+
elif not resolved_ids:
|
|
678
|
+
reason = f"No symbol found for '{module_fqn}.{symbol_name}'"
|
|
679
|
+
else:
|
|
680
|
+
reason = None
|
|
424
681
|
return PythonResolverResult(
|
|
425
|
-
resolved_ids=resolved_ids,
|
|
682
|
+
resolved_ids=resolved_ids,
|
|
683
|
+
unresolved_ids=unresolved_ids,
|
|
684
|
+
ambiguous_ids=ambiguous_ids,
|
|
685
|
+
reason=reason,
|
|
426
686
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
2
|
|
|
3
3
|
from deproc.core.interfaces.parser.models import SymbolID
|
|
4
|
+
from deproc.core.interfaces.resolver import ResolutionStatus
|
|
4
5
|
|
|
5
6
|
type ResolvedIDs = set[SymbolID]
|
|
6
7
|
type UnresolvedIDs = set[SymbolID]
|
|
@@ -10,3 +11,55 @@ type UnresolvedIDs = set[SymbolID]
|
|
|
10
11
|
class PythonResolverResult:
|
|
11
12
|
resolved_ids: ResolvedIDs
|
|
12
13
|
unresolved_ids: UnresolvedIDs
|
|
14
|
+
ambiguous_ids: set[SymbolID] = field(default_factory=set)
|
|
15
|
+
inaccessible_ids: set[SymbolID] = field(default_factory=set)
|
|
16
|
+
reason: str | None = None
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def status(self) -> ResolutionStatus:
|
|
20
|
+
if self.ambiguous_ids:
|
|
21
|
+
return ResolutionStatus.AMBIGUOUS
|
|
22
|
+
if self.resolved_ids:
|
|
23
|
+
return ResolutionStatus.RESOLVED
|
|
24
|
+
if self.inaccessible_ids:
|
|
25
|
+
return ResolutionStatus.INACCESSIBLE
|
|
26
|
+
return ResolutionStatus.UNRESOLVED
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def candidates(self) -> tuple[SymbolID, ...]:
|
|
30
|
+
return tuple(
|
|
31
|
+
sorted(self.ambiguous_ids or self.resolved_ids or self.inaccessible_ids)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class PythonBaseResolution:
|
|
37
|
+
name: str
|
|
38
|
+
status: ResolutionStatus
|
|
39
|
+
resolved_id: SymbolID | None = None
|
|
40
|
+
candidates: tuple[SymbolID, ...] = ()
|
|
41
|
+
reason: str | None = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class PythonClassMROResult:
|
|
46
|
+
status: ResolutionStatus
|
|
47
|
+
mro_ids: tuple[SymbolID, ...] = ()
|
|
48
|
+
bases: tuple[PythonBaseResolution, ...] = ()
|
|
49
|
+
reason: str | None = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(frozen=True)
|
|
53
|
+
class PythonInheritedMember:
|
|
54
|
+
member_id: SymbolID
|
|
55
|
+
owner_id: SymbolID
|
|
56
|
+
name: str
|
|
57
|
+
mro_depth: int
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True)
|
|
61
|
+
class PythonInheritedMembersResult:
|
|
62
|
+
status: ResolutionStatus
|
|
63
|
+
mro_ids: tuple[SymbolID, ...] = ()
|
|
64
|
+
members: tuple[PythonInheritedMember, ...] = ()
|
|
65
|
+
reason: str | None = None
|
|
@@ -85,13 +85,15 @@ def _compute_exports(
|
|
|
85
85
|
modules = groups.get(module_fqn, [])
|
|
86
86
|
names: set[str] = set()
|
|
87
87
|
explicit = False
|
|
88
|
-
|
|
88
|
+
explicit_names: set[str] = set()
|
|
89
|
+
own_dynamic = False
|
|
90
|
+
dependency_dynamic = False
|
|
89
91
|
for module in modules:
|
|
90
92
|
if getattr(module, "exports_dynamic", False):
|
|
91
|
-
|
|
93
|
+
own_dynamic = True
|
|
92
94
|
if module.all_exports is not None:
|
|
93
95
|
explicit = True
|
|
94
|
-
|
|
96
|
+
explicit_names.update(module.all_exports)
|
|
95
97
|
else:
|
|
96
98
|
names.update(_direct_exports(module, registry))
|
|
97
99
|
|
|
@@ -103,14 +105,21 @@ def _compute_exports(
|
|
|
103
105
|
continue
|
|
104
106
|
target_fqn = _module_target(import_statement, module, registry)
|
|
105
107
|
if not target_fqn:
|
|
106
|
-
|
|
108
|
+
dependency_dynamic = True
|
|
107
109
|
continue
|
|
108
110
|
if target_fqn in groups:
|
|
109
111
|
names.update(visit(target_fqn))
|
|
110
|
-
|
|
112
|
+
dependency_dynamic = (
|
|
113
|
+
dependency_dynamic or target_fqn in dynamic_modules
|
|
114
|
+
)
|
|
111
115
|
else:
|
|
112
|
-
|
|
116
|
+
dependency_dynamic = True
|
|
113
117
|
|
|
118
|
+
if explicit:
|
|
119
|
+
names = explicit_names
|
|
120
|
+
dynamic = own_dynamic
|
|
121
|
+
else:
|
|
122
|
+
dynamic = own_dynamic or dependency_dynamic
|
|
114
123
|
if not explicit and not modules:
|
|
115
124
|
dynamic = True
|
|
116
125
|
if dynamic:
|
|
@@ -33,3 +33,21 @@ def compute_mro_from_bases(
|
|
|
33
33
|
return [self_fqn, *c3_merge(merge_lists)]
|
|
34
34
|
except ValueError:
|
|
35
35
|
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def compute_mro_from_base_ids(
|
|
39
|
+
self_id: str,
|
|
40
|
+
base_mros: list[list[str] | None],
|
|
41
|
+
base_ids: list[str],
|
|
42
|
+
) -> list[str] | None:
|
|
43
|
+
"""Compute a C3 MRO while preserving entity identity."""
|
|
44
|
+
base_mro_lists: list[list[str]] = []
|
|
45
|
+
for mro in base_mros:
|
|
46
|
+
if mro is None:
|
|
47
|
+
return None
|
|
48
|
+
base_mro_lists.append(list(mro))
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
return [self_id, *c3_merge([*base_mro_lists, list(base_ids)])]
|
|
52
|
+
except ValueError:
|
|
53
|
+
return None
|
|
@@ -278,6 +278,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
278
278
|
end_lineno=meta.get("end_lineno", 0),
|
|
279
279
|
col_offset=meta.get("col_offset", 0),
|
|
280
280
|
end_col_offset=meta.get("end_col_offset", 0),
|
|
281
|
+
source_id=meta.get("source_id"),
|
|
281
282
|
)
|
|
282
283
|
common = {
|
|
283
284
|
"id": record["id"],
|
|
@@ -315,6 +316,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
315
316
|
)
|
|
316
317
|
return PythonFunctionLike(
|
|
317
318
|
name=record["name"],
|
|
319
|
+
parent_id=parent_id,
|
|
318
320
|
source_range=sr,
|
|
319
321
|
docstring_range=None,
|
|
320
322
|
signature=signature,
|
|
@@ -326,14 +328,19 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
326
328
|
if entity_class is PythonClass:
|
|
327
329
|
return PythonClass(
|
|
328
330
|
name=record["name"],
|
|
331
|
+
parent_id=parent_id,
|
|
329
332
|
source_range=sr,
|
|
330
333
|
docstring_range=None,
|
|
334
|
+
method_ids=meta.get("method_ids", []),
|
|
335
|
+
inner_type_ids=meta.get("inner_type_ids", []),
|
|
336
|
+
property_ids=meta.get("property_ids", []),
|
|
331
337
|
visibility=meta.get("visibility"),
|
|
332
338
|
inherits=meta.get("parent_classes", []),
|
|
333
339
|
**common,
|
|
334
340
|
)
|
|
335
341
|
if entity_class is PythonModule:
|
|
336
342
|
return PythonModule(
|
|
343
|
+
parent_id=parent_id,
|
|
337
344
|
all_exports=meta.get("all_exports"),
|
|
338
345
|
exports_dynamic=meta.get("exports_dynamic", False),
|
|
339
346
|
path=meta.get("path", ""),
|
|
@@ -348,6 +355,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
348
355
|
)
|
|
349
356
|
if entity_class is PythonPackage:
|
|
350
357
|
return PythonPackage(
|
|
358
|
+
parent_id=parent_id,
|
|
351
359
|
submodule_ids=meta.get("submodule_ids", []),
|
|
352
360
|
all_exports=meta.get("all_exports"),
|
|
353
361
|
exports_dynamic=meta.get("exports_dynamic", False),
|
|
@@ -363,6 +371,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
363
371
|
)
|
|
364
372
|
if entity_class is PythonNamespacePackage:
|
|
365
373
|
return PythonNamespacePackage(
|
|
374
|
+
parent_id=parent_id,
|
|
366
375
|
path=meta.get("path", ""),
|
|
367
376
|
submodule_ids=meta.get("submodule_ids", []),
|
|
368
377
|
**common,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
deproc/plugins/python/__init__.py,sha256=
|
|
1
|
+
deproc/plugins/python/__init__.py,sha256=JuMffHnYtF82voXTOP4m1hQ-zTGA5OeroWhHuz9v8nk,504
|
|
2
2
|
deproc/plugins/python/linker/__init__.py,sha256=gQ64CQcNEDHfvyAuYAz81PZ6r2V0ZdnsVOR2YZZvvfU,59
|
|
3
3
|
deproc/plugins/python/linker/main.py,sha256=rulxUoRRu4l7RbJKm2oBAxowHYv5KpsKvV36XRmvrjw,3260
|
|
4
4
|
deproc/plugins/python/linker/models.py,sha256=Q5_SFhaGyU8-HSNnIj0t00SYXqdnfwChyO6d5OcUNXM,492
|
|
@@ -8,17 +8,17 @@ deproc/plugins/python/parser/models.py,sha256=_Fr239_t-v6ET5EA1uUVTUiFHztqbJ03Q7
|
|
|
8
8
|
deproc/plugins/python/parser/utils/extraction.py,sha256=UE5u6SA_KrrGX6hTbuW1RrlFRvNqrlA-jMpGepHX0z0,7221
|
|
9
9
|
deproc/plugins/python/parser/utils/misc.py,sha256=vdxTcrNdWndIvaZtC8zGlKYI6XZnZHZ7I7YskuvXdnQ,219
|
|
10
10
|
deproc/plugins/python/parser/utils/tree_sitter_python.py,sha256=cBkzIlVjT1N7E7Vux9h5ixDF66M8UIn6ueo5OBz6yj0,814
|
|
11
|
-
deproc/plugins/python/resolver/__init__.py,sha256=
|
|
12
|
-
deproc/plugins/python/resolver/main.py,sha256=
|
|
13
|
-
deproc/plugins/python/resolver/models.py,sha256=
|
|
11
|
+
deproc/plugins/python/resolver/__init__.py,sha256=SBOVVzKlc-DxeXsrM3QYSm2qBjefA8h3Pm7wlhG0QwY,328
|
|
12
|
+
deproc/plugins/python/resolver/main.py,sha256=hPmX84x86EcOhAEdT1RbsgADv_jdGqsRANDBQjM7b24,25534
|
|
13
|
+
deproc/plugins/python/resolver/models.py,sha256=Q5BkCtjIoucj3VZw_YA1VN84y3aTDVLPT0RtlU64j-U,1766
|
|
14
14
|
deproc/plugins/python/symbol_cache/__init__.py,sha256=3Ob_B64ZY-_uA8QHkYJ3TBSD_S6wRW2E0cng42lqyrw,69
|
|
15
15
|
deproc/plugins/python/symbol_cache/main.py,sha256=lVoiscGkTGIN_ui-3DdKcKTys54vjeCtBdahEOGpLWA,2831
|
|
16
16
|
deproc/plugins/python/symbol_cache/models.py,sha256=1SgqUyhNnwZcITRCL8a-21T26niQ4DNtuaXs7bftXAc,284
|
|
17
|
-
deproc/plugins/python/utils/exports.py,sha256=
|
|
17
|
+
deproc/plugins/python/utils/exports.py,sha256=45dvBfClVEo_ZRN6vCPEx0VH3-eRQiKahv1Qgg074Lo,5218
|
|
18
18
|
deproc/plugins/python/utils/imports.py,sha256=DWvcN2SdYmhQgRl9RYAc5nxbbijSEtAJ11X_Xrf3x_U,547
|
|
19
|
-
deproc/plugins/python/utils/mro.py,sha256=
|
|
20
|
-
deproc/plugins/python/utils/serialization.py,sha256=
|
|
21
|
-
deproc_python-0.2.
|
|
22
|
-
deproc_python-0.2.
|
|
23
|
-
deproc_python-0.2.
|
|
24
|
-
deproc_python-0.2.
|
|
19
|
+
deproc/plugins/python/utils/mro.py,sha256=6tTC5lHFK2PZWX-454dGKNmiVhFDrMRQhI0bgDJZlrk,1565
|
|
20
|
+
deproc/plugins/python/utils/serialization.py,sha256=Lu5L2DLKCBhzCSQOykWq9tlFzqIMesL6JUWvrvZwExY,16657
|
|
21
|
+
deproc_python-0.2.1.dist-info/METADATA,sha256=9in_tQx9Za1v6HgNXPN5vi-LwNf9p80jCsSOUQfBICs,949
|
|
22
|
+
deproc_python-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
23
|
+
deproc_python-0.2.1.dist-info/top_level.txt,sha256=qyPIAnJVTLaewuAbLpShmn-777EtCI7b1b5sGgkzO10,7
|
|
24
|
+
deproc_python-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|