@suss/adapter-python 0.30.0 → 0.31.1

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.
package/dist/index.d.cts CHANGED
@@ -111,6 +111,8 @@ interface PythonPack {
111
111
  storage?: StoragePattern[];
112
112
  /** Which of the library's calls give back one of a model class. The README says what a chain of them composes into. */
113
113
  models?: PyModelQueries[];
114
+ /** Which of the library's classes return themselves from `__enter__`, so a `with` block gets the object itself. */
115
+ contextManagers?: PyContextManager[];
114
116
  /** How the library lets a project hand the database SQL it wrote itself. */
115
117
  rawSql?: RawSqlPattern[];
116
118
  }
@@ -211,6 +213,18 @@ interface RawSqlPattern {
211
213
  storageSystem: "postgresql" | "mysql" | "sqlite";
212
214
  }
213
215
  type PythonDiscoveryPattern = DecoratedClassRoute | DecoratedFunctionRoute;
216
+ /**
217
+ * A class whose `__enter__` gives back the object it was called on, so
218
+ * `with X() as y` makes y the `X()` the block opened. Python
219
+ * lets `__enter__` return anything, so only the library that wrote the
220
+ * class can say this, and a pack declares it for its own classes alone.
221
+ */
222
+ interface PyContextManager {
223
+ /** The module the classes come from, `httpx`. */
224
+ module: string;
225
+ /** The class names the library documents as returning self. */
226
+ returnsSelf: string[];
227
+ }
214
228
  /**
215
229
  * The callables a library gives a project for making a request. A
216
230
  * function that calls one of them is a client of the boundary that call
@@ -530,6 +544,11 @@ type Binding = {
530
544
  module: string;
531
545
  relativeLevel: number;
532
546
  localName: string;
547
+ /**
548
+ * False for `import a.b.c`, where the name binds the package `a`
549
+ * and a member read off it lands somewhere other than `module`.
550
+ */
551
+ bindsWholeModule: boolean;
533
552
  } | {
534
553
  kind: "importFrom";
535
554
  module: string;
@@ -609,23 +628,11 @@ type RoutePrefixResolution = {
609
628
  interface RouterIndex {
610
629
  resolve(pattern: PythonDiscoveryPattern, module: ModuleBinding, objectName: string): RoutePrefixResolution;
611
630
  /**
612
- * The same answer for a decorator whose object has no variable name to
613
- * look up, such as one written on `self.router`. The rules give the call
614
- * that built it, and every construction is already keyed by its call.
631
+ * The same for a decorator whose object has no variable name to look up,
632
+ * such as one written on `self.router`. The rules give the call that
633
+ * built it, and every construction is already keyed by its call.
615
634
  */
616
635
  resolveConstruction(pattern: PythonDiscoveryPattern, module: ModuleBinding, constructorName: string, constructionKey: string): RoutePrefixResolution;
617
- /**
618
- * The module-level def a name in another module refers to, with that
619
- * module's own bindings, so a decorator written through a project wrapper
620
- * can be read where the wrapper is written.
621
- */
622
- moduleDef(fromFile: string, spec: {
623
- module: string;
624
- relativeLevel: number;
625
- }, name: string): {
626
- node: Node;
627
- module: ModuleBinding;
628
- } | null;
629
636
  }
630
637
  interface RouterIndexOptions extends ModuleResolverOptions {
631
638
  /** The project's facts, so a loop over a call can be settled by the rules. */
@@ -727,7 +734,6 @@ interface DecoratorClassification {
727
734
  module: string | null;
728
735
  /** The local variable an attribute decorator hangs on, `app` in `@app.get(...)`. */
729
736
  objectName: string | null;
730
- relativeLevel: number;
731
737
  args: DecoratorArg[];
732
738
  keywordArgs: Record<string, DecoratorArg>;
733
739
  /** Where the decorator is written. Anything we read out of its arguments uses this as its provenance. */
@@ -739,16 +745,16 @@ interface DecoratorClassification {
739
745
  */
740
746
  objectModule?: ModuleBinding;
741
747
  /**
742
- * The call the rules say built the object this decorator hangs on, when
743
- * the lexical scope could not say. A router prefix is looked up by this
744
- * call rather than by a variable name, because there may not be one.
748
+ * The call the rules say built the object this decorator hangs on. A
749
+ * router the index never saw under a name is looked up by this call
750
+ * instead, and a decorator on `self.router` has no name to look up.
745
751
  */
746
752
  subjectConstruction?: {
747
753
  key: string;
748
754
  constructorName: string;
749
755
  };
750
756
  }
751
- declare function classifyDecorator(decoratorNode: Node, scope: Scope): DecoratorClassification;
757
+ declare function classifyDecorator(decoratorNode: Node, module: ModuleBinding, facts?: Database): DecoratorClassification;
752
758
 
753
759
  /**
754
760
  * What discovery uses for one file. `factsPath` is the path the facts were
@@ -1042,6 +1048,22 @@ interface ExtractPythonResult {
1042
1048
  summaries: BehavioralSummary[];
1043
1049
  facts: Database;
1044
1050
  }
1051
+ /** One parsed file and the packs a run over it would load. */
1052
+ interface FileFactsOptions {
1053
+ file: string;
1054
+ root: Node;
1055
+ module: ModuleBinding;
1056
+ packs: readonly PythonPack[];
1057
+ }
1058
+ /**
1059
+ * The facts for a single parsed file, with the evaluator bound to them,
1060
+ * for a caller that has one file and no project. A pack's own tests need
1061
+ * these: what built a receiver is an answer the rules give, and without
1062
+ * facts they have nothing to give it from. A project run emits the same
1063
+ * facts across every file at once, so a name written in another file
1064
+ * resolves there and never here.
1065
+ */
1066
+ declare function factsForFile(options: FileFactsOptions): Database;
1045
1067
  declare function extractPythonProject(options: ExtractPythonOptions): Promise<ExtractPythonResult>;
1046
1068
  /** Every `.py` file under `root`, depth-first, skipping the usual non-source directories. */
1047
1069
  declare function findPythonFiles(root: string): string[];
@@ -1090,4 +1112,4 @@ declare function pythonImportEvidence(options: PythonImportEvidenceOptions): Pro
1090
1112
  */
1091
1113
  declare const ADAPTER_VERSION = "0.1.0";
1092
1114
 
1093
- export { ADAPTER_VERSION, type AnnotationContext, type Binding, type BoundPythonFile, type DecoratedClassRoute, type DecoratedFunctionRoute, type DecoratorArg, type DecoratorClassification, type DiscoveryOptions, type ExtractPythonOptions, type ExtractPythonResult, type ModuleBinding, type ModuleResolution, type ModuleResolverOptions, type MountObjectCarrier, type MountObjectPrefix, type MountPrefixEffect, type NoValuePrefix, type PathRepeatedSlashes, type PrefixTrailingSlash, type PyModelEntryFunction, type PyModelEntryMethod, type PyModelQueries, type PyStatusCall, type PythonDiscoveryPattern, type PythonImportEvidence, type PythonImportEvidenceOptions, type PythonImportSite, type PythonPack, type PythonValueHandle, PythonWhySession, type PythonWhySessionOptions, type RawSqlPattern, type RelativeModuleSpec, type RouteConventions, type RoutePrefixResolution, type RouterComposition, type RouterIndex, type Scope, type ScopeKind, type StoragePattern, annotationToShape, bindModule, buildRouterIndex, classifyDecorator, containedValues, discoverUnits, emitEntryFact, emitModuleImportFacts, emitValueFacts, extractPythonProject, findPythonFiles, nameKeyIn, nodeId, objectReturnedBy, parsePython, parsePythonSync, preloadPythonGrammar, pythonImportEvidence, readKey, resolveAbsoluteModule, resolveCalls, resolveModule, resolveName, resolveRelativeModule, shapeFromName, unitKey };
1115
+ export { ADAPTER_VERSION, type AnnotationContext, type Binding, type BoundPythonFile, type DecoratedClassRoute, type DecoratedFunctionRoute, type DecoratorArg, type DecoratorClassification, type DiscoveryOptions, type ExtractPythonOptions, type ExtractPythonResult, type FileFactsOptions, type ModuleBinding, type ModuleResolution, type ModuleResolverOptions, type MountObjectCarrier, type MountObjectPrefix, type MountPrefixEffect, type NoValuePrefix, type PathRepeatedSlashes, type PrefixTrailingSlash, type PyModelEntryFunction, type PyModelEntryMethod, type PyModelQueries, type PyStatusCall, type PythonDiscoveryPattern, type PythonImportEvidence, type PythonImportEvidenceOptions, type PythonImportSite, type PythonPack, type PythonValueHandle, PythonWhySession, type PythonWhySessionOptions, type RawSqlPattern, type RelativeModuleSpec, type RouteConventions, type RoutePrefixResolution, type RouterComposition, type RouterIndex, type Scope, type ScopeKind, type StoragePattern, annotationToShape, bindModule, buildRouterIndex, classifyDecorator, containedValues, discoverUnits, emitEntryFact, emitModuleImportFacts, emitValueFacts, extractPythonProject, factsForFile, findPythonFiles, nameKeyIn, nodeId, objectReturnedBy, parsePython, parsePythonSync, preloadPythonGrammar, pythonImportEvidence, readKey, resolveAbsoluteModule, resolveCalls, resolveModule, resolveName, resolveRelativeModule, shapeFromName, unitKey };
package/dist/index.d.ts CHANGED
@@ -111,6 +111,8 @@ interface PythonPack {
111
111
  storage?: StoragePattern[];
112
112
  /** Which of the library's calls give back one of a model class. The README says what a chain of them composes into. */
113
113
  models?: PyModelQueries[];
114
+ /** Which of the library's classes return themselves from `__enter__`, so a `with` block gets the object itself. */
115
+ contextManagers?: PyContextManager[];
114
116
  /** How the library lets a project hand the database SQL it wrote itself. */
115
117
  rawSql?: RawSqlPattern[];
116
118
  }
@@ -211,6 +213,18 @@ interface RawSqlPattern {
211
213
  storageSystem: "postgresql" | "mysql" | "sqlite";
212
214
  }
213
215
  type PythonDiscoveryPattern = DecoratedClassRoute | DecoratedFunctionRoute;
216
+ /**
217
+ * A class whose `__enter__` gives back the object it was called on, so
218
+ * `with X() as y` makes y the `X()` the block opened. Python
219
+ * lets `__enter__` return anything, so only the library that wrote the
220
+ * class can say this, and a pack declares it for its own classes alone.
221
+ */
222
+ interface PyContextManager {
223
+ /** The module the classes come from, `httpx`. */
224
+ module: string;
225
+ /** The class names the library documents as returning self. */
226
+ returnsSelf: string[];
227
+ }
214
228
  /**
215
229
  * The callables a library gives a project for making a request. A
216
230
  * function that calls one of them is a client of the boundary that call
@@ -530,6 +544,11 @@ type Binding = {
530
544
  module: string;
531
545
  relativeLevel: number;
532
546
  localName: string;
547
+ /**
548
+ * False for `import a.b.c`, where the name binds the package `a`
549
+ * and a member read off it lands somewhere other than `module`.
550
+ */
551
+ bindsWholeModule: boolean;
533
552
  } | {
534
553
  kind: "importFrom";
535
554
  module: string;
@@ -609,23 +628,11 @@ type RoutePrefixResolution = {
609
628
  interface RouterIndex {
610
629
  resolve(pattern: PythonDiscoveryPattern, module: ModuleBinding, objectName: string): RoutePrefixResolution;
611
630
  /**
612
- * The same answer for a decorator whose object has no variable name to
613
- * look up, such as one written on `self.router`. The rules give the call
614
- * that built it, and every construction is already keyed by its call.
631
+ * The same for a decorator whose object has no variable name to look up,
632
+ * such as one written on `self.router`. The rules give the call that
633
+ * built it, and every construction is already keyed by its call.
615
634
  */
616
635
  resolveConstruction(pattern: PythonDiscoveryPattern, module: ModuleBinding, constructorName: string, constructionKey: string): RoutePrefixResolution;
617
- /**
618
- * The module-level def a name in another module refers to, with that
619
- * module's own bindings, so a decorator written through a project wrapper
620
- * can be read where the wrapper is written.
621
- */
622
- moduleDef(fromFile: string, spec: {
623
- module: string;
624
- relativeLevel: number;
625
- }, name: string): {
626
- node: Node;
627
- module: ModuleBinding;
628
- } | null;
629
636
  }
630
637
  interface RouterIndexOptions extends ModuleResolverOptions {
631
638
  /** The project's facts, so a loop over a call can be settled by the rules. */
@@ -727,7 +734,6 @@ interface DecoratorClassification {
727
734
  module: string | null;
728
735
  /** The local variable an attribute decorator hangs on, `app` in `@app.get(...)`. */
729
736
  objectName: string | null;
730
- relativeLevel: number;
731
737
  args: DecoratorArg[];
732
738
  keywordArgs: Record<string, DecoratorArg>;
733
739
  /** Where the decorator is written. Anything we read out of its arguments uses this as its provenance. */
@@ -739,16 +745,16 @@ interface DecoratorClassification {
739
745
  */
740
746
  objectModule?: ModuleBinding;
741
747
  /**
742
- * The call the rules say built the object this decorator hangs on, when
743
- * the lexical scope could not say. A router prefix is looked up by this
744
- * call rather than by a variable name, because there may not be one.
748
+ * The call the rules say built the object this decorator hangs on. A
749
+ * router the index never saw under a name is looked up by this call
750
+ * instead, and a decorator on `self.router` has no name to look up.
745
751
  */
746
752
  subjectConstruction?: {
747
753
  key: string;
748
754
  constructorName: string;
749
755
  };
750
756
  }
751
- declare function classifyDecorator(decoratorNode: Node, scope: Scope): DecoratorClassification;
757
+ declare function classifyDecorator(decoratorNode: Node, module: ModuleBinding, facts?: Database): DecoratorClassification;
752
758
 
753
759
  /**
754
760
  * What discovery uses for one file. `factsPath` is the path the facts were
@@ -1042,6 +1048,22 @@ interface ExtractPythonResult {
1042
1048
  summaries: BehavioralSummary[];
1043
1049
  facts: Database;
1044
1050
  }
1051
+ /** One parsed file and the packs a run over it would load. */
1052
+ interface FileFactsOptions {
1053
+ file: string;
1054
+ root: Node;
1055
+ module: ModuleBinding;
1056
+ packs: readonly PythonPack[];
1057
+ }
1058
+ /**
1059
+ * The facts for a single parsed file, with the evaluator bound to them,
1060
+ * for a caller that has one file and no project. A pack's own tests need
1061
+ * these: what built a receiver is an answer the rules give, and without
1062
+ * facts they have nothing to give it from. A project run emits the same
1063
+ * facts across every file at once, so a name written in another file
1064
+ * resolves there and never here.
1065
+ */
1066
+ declare function factsForFile(options: FileFactsOptions): Database;
1045
1067
  declare function extractPythonProject(options: ExtractPythonOptions): Promise<ExtractPythonResult>;
1046
1068
  /** Every `.py` file under `root`, depth-first, skipping the usual non-source directories. */
1047
1069
  declare function findPythonFiles(root: string): string[];
@@ -1090,4 +1112,4 @@ declare function pythonImportEvidence(options: PythonImportEvidenceOptions): Pro
1090
1112
  */
1091
1113
  declare const ADAPTER_VERSION = "0.1.0";
1092
1114
 
1093
- export { ADAPTER_VERSION, type AnnotationContext, type Binding, type BoundPythonFile, type DecoratedClassRoute, type DecoratedFunctionRoute, type DecoratorArg, type DecoratorClassification, type DiscoveryOptions, type ExtractPythonOptions, type ExtractPythonResult, type ModuleBinding, type ModuleResolution, type ModuleResolverOptions, type MountObjectCarrier, type MountObjectPrefix, type MountPrefixEffect, type NoValuePrefix, type PathRepeatedSlashes, type PrefixTrailingSlash, type PyModelEntryFunction, type PyModelEntryMethod, type PyModelQueries, type PyStatusCall, type PythonDiscoveryPattern, type PythonImportEvidence, type PythonImportEvidenceOptions, type PythonImportSite, type PythonPack, type PythonValueHandle, PythonWhySession, type PythonWhySessionOptions, type RawSqlPattern, type RelativeModuleSpec, type RouteConventions, type RoutePrefixResolution, type RouterComposition, type RouterIndex, type Scope, type ScopeKind, type StoragePattern, annotationToShape, bindModule, buildRouterIndex, classifyDecorator, containedValues, discoverUnits, emitEntryFact, emitModuleImportFacts, emitValueFacts, extractPythonProject, findPythonFiles, nameKeyIn, nodeId, objectReturnedBy, parsePython, parsePythonSync, preloadPythonGrammar, pythonImportEvidence, readKey, resolveAbsoluteModule, resolveCalls, resolveModule, resolveName, resolveRelativeModule, shapeFromName, unitKey };
1115
+ export { ADAPTER_VERSION, type AnnotationContext, type Binding, type BoundPythonFile, type DecoratedClassRoute, type DecoratedFunctionRoute, type DecoratorArg, type DecoratorClassification, type DiscoveryOptions, type ExtractPythonOptions, type ExtractPythonResult, type FileFactsOptions, type ModuleBinding, type ModuleResolution, type ModuleResolverOptions, type MountObjectCarrier, type MountObjectPrefix, type MountPrefixEffect, type NoValuePrefix, type PathRepeatedSlashes, type PrefixTrailingSlash, type PyModelEntryFunction, type PyModelEntryMethod, type PyModelQueries, type PyStatusCall, type PythonDiscoveryPattern, type PythonImportEvidence, type PythonImportEvidenceOptions, type PythonImportSite, type PythonPack, type PythonValueHandle, PythonWhySession, type PythonWhySessionOptions, type RawSqlPattern, type RelativeModuleSpec, type RouteConventions, type RoutePrefixResolution, type RouterComposition, type RouterIndex, type Scope, type ScopeKind, type StoragePattern, annotationToShape, bindModule, buildRouterIndex, classifyDecorator, containedValues, discoverUnits, emitEntryFact, emitModuleImportFacts, emitValueFacts, extractPythonProject, factsForFile, findPythonFiles, nameKeyIn, nodeId, objectReturnedBy, parsePython, parsePythonSync, preloadPythonGrammar, pythonImportEvidence, readKey, resolveAbsoluteModule, resolveCalls, resolveModule, resolveName, resolveRelativeModule, shapeFromName, unitKey };