jsii-pacmak 1.63.2 → 1.65.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.
@@ -26,7 +26,7 @@ const DOCSTRING_QUOTES = "'''";
26
26
  class Python extends target_1.Target {
27
27
  constructor(options) {
28
28
  super(options);
29
- this.generator = new PythonGenerator(options.rosetta);
29
+ this.generator = new PythonGenerator(options.rosetta, options);
30
30
  }
31
31
  async generateCode(outDir, tarball) {
32
32
  await super.generateCode(outDir, tarball);
@@ -394,6 +394,7 @@ class BaseMethod {
394
394
  const paramType = (0, type_name_1.toTypeName)(prop.prop).pythonType({
395
395
  ...context,
396
396
  parameterType: true,
397
+ typeAnnotation: true,
397
398
  });
398
399
  const paramDefault = prop.prop.optional ? ' = None' : '';
399
400
  pythonParams.push(`${paramName}: ${paramType}${paramDefault}`);
@@ -419,7 +420,6 @@ class BaseMethod {
419
420
  }
420
421
  const decorators = new Array();
421
422
  if (this.jsName !== undefined) {
422
- // "# type: ignore[misc]" needed because mypy does not know how to check decorated declarations
423
423
  decorators.push(`@jsii.member(jsii_name="${this.jsName}")`);
424
424
  }
425
425
  if (this.decorator !== undefined) {
@@ -429,22 +429,19 @@ class BaseMethod {
429
429
  decorators.push('@abc.abstractmethod');
430
430
  }
431
431
  if (decorators.length > 0) {
432
- // "# type: ignore[misc]" needed because mypy does not know how to check decorated declarations
433
- for (const decorator of decorators
434
- .join(' # type: ignore[misc]\n')
435
- .split('\n')) {
432
+ for (const decorator of decorators) {
436
433
  code.line(decorator);
437
434
  }
438
435
  }
439
436
  pythonParams.unshift(slugifyAsNeeded(this.implicitParameter, pythonParams.map((param) => param.split(':')[0].trim())));
440
- openSignature(code, 'def', this.pythonName, pythonParams, false, returnType);
437
+ openSignature(code, 'def', this.pythonName, pythonParams, returnType);
441
438
  this.generator.emitDocString(code, this.apiLocation, this.docs, {
442
439
  arguments: documentableArgs,
443
440
  documentableItem: `method-${this.pythonName}`,
444
441
  });
445
442
  if ((this.shouldEmitBody || forceEmitBody) &&
446
443
  (!renderAbstract || !this.abstract)) {
447
- emitParameterTypeChecks(code, pythonParams.slice(1), `${(0, type_name_1.toPythonFullName)(this.parent.fqn, context.assembly)}.${this.pythonName}`);
444
+ emitParameterTypeChecks(code, context, pythonParams.slice(1), `${(0, type_name_1.toPythonFullName)(this.parent.fqn, context.assembly)}.${this.pythonName}`);
448
445
  }
449
446
  this.emitBody(code, context, renderAbstract, forceEmitBody, liftedPropNames, pythonParams[0], returnType);
450
447
  code.closeBlock();
@@ -567,13 +564,17 @@ class BaseProperty {
567
564
  emit(code, context, opts) {
568
565
  const { renderAbstract = true, forceEmitBody = false } = opts ?? {};
569
566
  const pythonType = (0, type_name_1.toTypeName)(this.type).pythonType(context);
570
- // "# type: ignore[misc]" is needed because mypy cannot check decorated things
571
- code.line(`@${this.decorator} # type: ignore[misc]`);
567
+ code.line(`@${this.decorator}`);
572
568
  code.line(`@jsii.member(jsii_name="${this.jsName}")`);
573
569
  if (renderAbstract && this.abstract) {
574
570
  code.line('@abc.abstractmethod');
575
571
  }
576
- openSignature(code, 'def', this.pythonName, [this.implicitParameter], true, pythonType);
572
+ openSignature(code, 'def', this.pythonName, [this.implicitParameter], pythonType,
573
+ // PyRight and MyPY both special-case @property, but not custom implementations such as our @classproperty...
574
+ // MyPY reports on the re-declaration, but PyRight reports on the initial declaration (duh!)
575
+ this.isStatic && !this.immutable
576
+ ? 'pyright: ignore [reportGeneralTypeIssues]'
577
+ : undefined);
577
578
  this.generator.emitDocString(code, this.apiLocation, this.docs, {
578
579
  documentableItem: `prop-${this.pythonName}`,
579
580
  });
@@ -588,14 +589,16 @@ class BaseProperty {
588
589
  code.closeBlock();
589
590
  if (!this.immutable) {
590
591
  code.line();
592
+ // PyRight and MyPY both special-case @property, but not custom implementations such as our @classproperty...
593
+ // MyPY reports on the re-declaration, but PyRight reports on the initial declaration (duh!)
591
594
  code.line(`@${this.pythonName}.setter${this.isStatic ? ' # type: ignore[no-redef]' : ''}`);
592
595
  if (renderAbstract && this.abstract) {
593
596
  code.line('@abc.abstractmethod');
594
597
  }
595
- openSignature(code, 'def', this.pythonName, [this.implicitParameter, `value: ${pythonType}`], false, 'None');
598
+ openSignature(code, 'def', this.pythonName, [this.implicitParameter, `value: ${pythonType}`], 'None');
596
599
  if ((this.shouldEmitBody || forceEmitBody) &&
597
600
  (!renderAbstract || !this.abstract)) {
598
- emitParameterTypeChecks(code, [`value: ${pythonType}`],
601
+ emitParameterTypeChecks(code, context, [`value: ${pythonType}`],
599
602
  // In order to get a property accessor, we must resort to getting the
600
603
  // attribute on the type, instead of the value (where the getter would
601
604
  // be implicitly invoked for us...)
@@ -732,7 +735,7 @@ class Struct extends BasePythonClassType {
732
735
  const constructorArguments = kwargs.length > 0
733
736
  ? [implicitParameter, '*', ...kwargs]
734
737
  : [implicitParameter];
735
- openSignature(code, 'def', '__init__', constructorArguments, false, 'None');
738
+ openSignature(code, 'def', '__init__', constructorArguments, 'None');
736
739
  this.emitConstructorDocstring(code);
737
740
  // Re-type struct arguments that were passed as "dict". Do this before validating argument types...
738
741
  for (const member of members.filter((m) => m.isStruct(this.generator))) {
@@ -745,7 +748,7 @@ class Struct extends BasePythonClassType {
745
748
  code.line(`${member.pythonName} = ${typeName}(**${member.pythonName})`);
746
749
  code.closeBlock();
747
750
  }
748
- emitParameterTypeChecks(code, kwargs, `${(0, type_name_1.toPythonFullName)(this.spec.fqn, context.assembly)}.__init__`);
751
+ emitParameterTypeChecks(code, context, kwargs, `${(0, type_name_1.toPythonFullName)(this.spec.fqn, context.assembly)}.__init__`);
749
752
  // Required properties, those will always be put into the dict
750
753
  assignDictionary(code, `${implicitParameter}._values: typing.Dict[str, typing.Any]`, members
751
754
  .filter((m) => !m.optional)
@@ -772,7 +775,7 @@ class Struct extends BasePythonClassType {
772
775
  emitGetter(member, code, context) {
773
776
  const pythonType = member.typeAnnotation(context);
774
777
  code.line('@builtins.property');
775
- openSignature(code, 'def', member.pythonName, ['self'], true, pythonType);
778
+ openSignature(code, 'def', member.pythonName, ['self'], pythonType);
776
779
  member.emitDocString(code);
777
780
  // NOTE: No parameter to validate here, this is a getter.
778
781
  code.line(`result = self._values.get(${JSON.stringify(member.pythonName)})`);
@@ -1483,6 +1486,12 @@ class Package {
1483
1486
  .reduce((buildTools, entry) => (entry ? [...buildTools, entry] : buildTools), new Array());
1484
1487
  code.line(`requires = [${buildTools.map((x) => `"${x}"`).join(', ')}]`);
1485
1488
  code.line('build-backend = "setuptools.build_meta"');
1489
+ code.line();
1490
+ code.line('[tool.pyright]');
1491
+ code.line('defineConstant = { DEBUG = true }');
1492
+ code.line('pythonVersion = "3.7"');
1493
+ code.line('pythonPlatform = "All"');
1494
+ code.line('reportSelfClsParameterName = false');
1486
1495
  code.closeFile('pyproject.toml');
1487
1496
  // We also need to write out a MANIFEST.in to ensure that all of our required
1488
1497
  // files are included.
@@ -1575,7 +1584,7 @@ class TypeResolver {
1575
1584
  }
1576
1585
  }
1577
1586
  class PythonGenerator extends generator_1.Generator {
1578
- constructor(rosetta, options = {}) {
1587
+ constructor(rosetta, options) {
1579
1588
  super(options);
1580
1589
  this.rosetta = rosetta;
1581
1590
  this.code.openBlockFormatter = (s) => `${s}:`;
@@ -1723,6 +1732,7 @@ class PythonGenerator extends generator_1.Generator {
1723
1732
  assembly: assm,
1724
1733
  emittedTypes: new Set(),
1725
1734
  resolver,
1735
+ runtimeTypeChecking: this.runtimeTypeChecking,
1726
1736
  submodule: assm.name,
1727
1737
  typeResolver: (fqn) => resolver.dereference(fqn),
1728
1738
  });
@@ -1972,7 +1982,7 @@ function slugifyAsNeeded(name, inUse) {
1972
1982
  //
1973
1983
  // @see https://black.readthedocs.io/en/stable/the_black_code_style.html
1974
1984
  const TARGET_LINE_LENGTH = 88;
1975
- function openSignature(code, keyword, name, params, trailingComma = false, returnType) {
1985
+ function openSignature(code, keyword, name, params, returnType, lineComment) {
1976
1986
  const prefix = `${keyword} ${name}`;
1977
1987
  const suffix = returnType ? ` -> ${returnType}` : '';
1978
1988
  if (params.length === 0) {
@@ -1981,8 +1991,8 @@ function openSignature(code, keyword, name, params, trailingComma = false, retur
1981
1991
  }
1982
1992
  const join = ', ';
1983
1993
  const { elementsSize, joinSize } = totalSizeOf(params, join);
1984
- const hasComments = !params.some((param) => /# .+$/.exec(param));
1985
- if (hasComments &&
1994
+ const hasComments = params.some((param) => /#\s*.+$/.exec(param) != null);
1995
+ if (!hasComments &&
1986
1996
  TARGET_LINE_LENGTH >
1987
1997
  code.currentIndentLength +
1988
1998
  prefix.length +
@@ -1990,25 +2000,15 @@ function openSignature(code, keyword, name, params, trailingComma = false, retur
1990
2000
  joinSize +
1991
2001
  suffix.length +
1992
2002
  2) {
1993
- code.openBlock(`${prefix}(${params.join(join)})${suffix}`);
2003
+ code.indent(`${prefix}(${params.join(join)})${suffix}:${lineComment ? ` # ${lineComment}` : ''}`);
1994
2004
  return;
1995
2005
  }
1996
2006
  code.indent(`${prefix}(`);
1997
- if (!hasComments &&
1998
- TARGET_LINE_LENGTH >
1999
- code.currentIndentLength +
2000
- elementsSize +
2001
- joinSize +
2002
- (trailingComma ? 1 : 0)) {
2003
- code.line(`${params.join(join)}${trailingComma ? ',' : ''}`);
2004
- }
2005
- else {
2006
- for (const param of params) {
2007
- code.line(param.replace(/(\s*# .+)?$/, ',$1'));
2008
- }
2007
+ for (const param of params) {
2008
+ code.line(param.replace(/(\s*# .+)?$/, ',$1'));
2009
2009
  }
2010
2010
  code.unindent(false);
2011
- code.openBlock(`)${suffix}`);
2011
+ code.indent(`)${suffix}:${lineComment ? ` # ${lineComment}` : ''}`);
2012
2012
  }
2013
2013
  /**
2014
2014
  * Emits runtime type checking code for parameters.
@@ -2017,9 +2017,12 @@ function openSignature(code, keyword, name, params, trailingComma = false, retur
2017
2017
  * @param params the parameter signatures to be type-checked.
2018
2018
  * @param typedEntity the type-annotated entity.
2019
2019
  */
2020
- function emitParameterTypeChecks(code, params, typedEntity) {
2020
+ function emitParameterTypeChecks(code, context, params, typedEntity) {
2021
+ if (!context.runtimeTypeChecking) {
2022
+ return;
2023
+ }
2021
2024
  const paramInfo = params.map((param) => {
2022
- const [name] = param.split(/\s*[:=]\s*/, 1);
2025
+ const [name] = param.split(/\s*[:=#]\s*/, 1);
2023
2026
  if (name === '*') {
2024
2027
  return { kwargsMark: true };
2025
2028
  }
@@ -2044,11 +2047,14 @@ function emitParameterTypeChecks(code, params, typedEntity) {
2044
2047
  openedBlock = true;
2045
2048
  }
2046
2049
  let expectedType = `${typesVar}[${JSON.stringify(name)}]`;
2050
+ let comment = '';
2047
2051
  if (is_rest) {
2048
2052
  // This is a vararg, so the value will appear as a tuple.
2049
2053
  expectedType = `typing.Tuple[${expectedType}, ...]`;
2054
+ // Need to ignore reportGeneralTypeIssues because pyright incorrectly parses that as a type annotation 😒
2055
+ comment = ' # pyright: ignore [reportGeneralTypeIssues]';
2050
2056
  }
2051
- code.line(`check_type(argname=${JSON.stringify(`argument ${name}`)}, value=${name}, expected_type=${expectedType})`);
2057
+ code.line(`check_type(argname=${JSON.stringify(`argument ${name}`)}, value=${name}, expected_type=${expectedType})${comment}`);
2052
2058
  }
2053
2059
  if (openedBlock) {
2054
2060
  code.closeBlock();
@@ -72,7 +72,7 @@ exports.toPythonVersionRange = toPythonVersionRange;
72
72
  * @returns the version that should be serialized
73
73
  */
74
74
  function toReleaseVersion(assemblyVersion, target) {
75
- const version = (0, semver_1.parse)(assemblyVersion, { includePrerelease: true });
75
+ const version = (0, semver_1.parse)(assemblyVersion);
76
76
  if (version == null) {
77
77
  throw new Error(`Unable to parse the provided assembly version: "${assemblyVersion}"`);
78
78
  }
package/lib/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** The short version number for this JSII compiler (e.g: `X.Y.Z`) */
2
- export declare const VERSION = "1.63.2";
2
+ export declare const VERSION = "1.65.1";
3
3
  /** The qualified version number for this JSII compiler (e.g: `X.Y.Z (build #######)`) */
4
- export declare const VERSION_DESC = "1.63.2 (build a8a8833)";
4
+ export declare const VERSION_DESC = "1.65.1 (build b0947e4)";
5
5
  //# sourceMappingURL=version.d.ts.map
package/lib/version.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
- // Generated at 2022-07-29T15:35:51Z by generate.sh
2
+ // Generated at 2022-08-29T17:36:17Z by generate.sh
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.VERSION_DESC = exports.VERSION = void 0;
5
5
  /** The short version number for this JSII compiler (e.g: `X.Y.Z`) */
6
- exports.VERSION = '1.63.2';
6
+ exports.VERSION = '1.65.1';
7
7
  /** The qualified version number for this JSII compiler (e.g: `X.Y.Z (build #######)`) */
8
- exports.VERSION_DESC = '1.63.2 (build a8a8833)';
8
+ exports.VERSION_DESC = '1.65.1 (build b0947e4)';
9
9
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsii-pacmak",
3
- "version": "1.63.2",
3
+ "version": "1.65.1",
4
4
  "description": "A code generation framework for jsii backend languages",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,32 +37,35 @@
37
37
  "package": "package-js"
38
38
  },
39
39
  "dependencies": {
40
- "@jsii/check-node": "1.63.2",
41
- "@jsii/spec": "^1.63.2",
40
+ "@jsii/check-node": "1.65.1",
41
+ "@jsii/spec": "^1.65.1",
42
42
  "clone": "^2.1.2",
43
- "codemaker": "^1.63.2",
43
+ "codemaker": "^1.65.1",
44
44
  "commonmark": "^0.30.0",
45
45
  "escape-string-regexp": "^4.0.0",
46
46
  "fs-extra": "^10.1.0",
47
- "jsii-reflect": "^1.63.2",
48
- "jsii-rosetta": "^1.63.2",
47
+ "jsii-reflect": "^1.65.1",
48
+ "jsii-rosetta": "^1.65.1",
49
49
  "semver": "^7.3.7",
50
50
  "spdx-license-list": "^6.6.0",
51
51
  "xmlbuilder": "^15.1.1",
52
52
  "yargs": "^16.2.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@jsii/dotnet-runtime": "^1.63.2",
56
- "@jsii/java-runtime": "^1.63.2",
57
- "@jsii/go-runtime": "^1.63.2",
58
- "@scope/jsii-calc-lib": "^1.63.2",
55
+ "@jsii/dotnet-runtime": "^1.65.1",
56
+ "@jsii/java-runtime": "^1.65.1",
57
+ "@jsii/go-runtime": "^1.65.1",
58
+ "@scope/jsii-calc-lib": "^1.65.1",
59
59
  "@types/clone": "^2.1.1",
60
+ "@types/diff": "^5.0.2",
60
61
  "@types/commonmark": "^0.27.5",
61
62
  "@types/fs-extra": "^9.0.13",
62
63
  "@types/semver": "^7.3.10",
63
- "jsii": "^1.63.2",
64
- "jsii-build-tools": "^1.63.2",
65
- "jsii-calc": "^3.20.120"
64
+ "diff": "^5.1.0",
65
+ "jsii": "^1.65.1",
66
+ "jsii-build-tools": "^1.65.1",
67
+ "jsii-calc": "^3.20.120",
68
+ "pyright": "^1.1.266"
66
69
  },
67
70
  "keywords": [
68
71
  "jsii",