Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): encode positional-only arguments in signatures #4197

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
with:
cache: yarn
node-version: '16'
- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: '3.8'
cache: pip
- name: Install python3-venv
run: sudo apt install -y python3-venv
Expand Down Expand Up @@ -130,10 +130,10 @@ jobs:
with:
cache: yarn
node-version: '16'
- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: '3.8'
cache: pip
- name: Install python3-venv
run: sudo apt install -y python3-venv
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
java: ['8']
node: ['16'] # EOL 2023-09-11
os: [ubuntu-latest]
python: ['3.7']
python: ['3.8']
# Add specific combinations to be tested against "node 14" (to restrict cardinality)
include:
# Test using Windows
Expand All @@ -207,69 +207,62 @@ jobs:
go: '1.18'
java: '8'
node: '16'
python: '3.7'
python: '3.8'
# Test using macOS
- title: 'macOS'
os: macos-latest
dotnet: '6.0.x'
go: '1.18'
java: '8'
node: '16'
python: '3.7'
python: '3.8'
# Test alternate Nodes
- title: 'Node 16'
java: '8'
dotnet: '6.0.x'
go: '1.18'
node: '16' # EOL 2023-09-11
os: ubuntu-latest
python: '3.7'
python: '3.8'
- title: 'Node 18'
java: '8'
dotnet: '6.0.x'
go: '1.18'
node: '18' # EOL 2025-04-30
os: ubuntu-latest
python: '3.7'
python: '3.8'
- title: 'Node 20'
java: '8'
dotnet: '6.0.x'
go: '1.18'
node: '20' # EOL 2026-04-30
os: ubuntu-latest
python: '3.7'
python: '3.8'
# Test alternate .NETs
- title: '.NET 7.0'
java: '8'
dotnet: '7.0.x'
go: '1.18'
node: '16'
os: ubuntu-latest
python: '3.7'
python: '3.8'
# Test alternate Gos
- title: 'Go 1.19'
java: '8'
dotnet: '6.0.x'
go: '1.19'
node: '16'
os: ubuntu-latest
python: '3.7'
python: '3.8'
# Test alternate Javas
- title: 'Java 11'
java: '11'
dotnet: '6.0.x'
go: '1.18'
node: '16'
os: ubuntu-latest
python: '3.7'
# Test alternate Pythons
- title: 'Python 3.8'
python: '3.8'
dotnet: '6.0.x'
go: '1.18'
java: '8'
node: '16'
os: ubuntu-latest
# Test alternate Pythons
- title: 'Python 3.9'
python: '3.9'
dotnet: '6.0.x'
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ in your development environment.
+ [`maven >= 3.0.5`](https://maven.apache.org)
- [.NET `6.0`] or later
+ *Recommended:* [`mono >= 6`](https://www.mono-project.com)
- [Python `3.7.3`] or later
- [Python `3.8`] or later
+ [`pip`](https://pip.pypa.io/en/stable/installing/)
+ [`setuptools >= 38.6.0`](https://pypi.org/project/setuptools/)
+ [`wheel`](https://pypi.org/project/wheel/)
Expand All @@ -57,7 +57,7 @@ in your development environment.
[Oracle's OpenJDK8]: http://openjdk.java.net/install/
[Amazon Corretto 8]: https://aws.amazon.com/corretto/
[.NET `6.0`]: https://www.microsoft.com/net/download
[Python `3.7.3`]: https://www.python.org/downloads/release/python-373/
[Python `3.8`]: https://www.python.org/downloads/
[Go]: https://go.dev/dl/

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion gh-pages/content/user-guides/language-support/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ in significant re-engineering effort:
- How are dependencies modeled? If [semantic versioning] is not the norm, what is the strategy to correctly represent
semantic version ranges?
- What are the toolchain and platform requirements?
- For example, **Java** requires an OpenJDK 8 distribution and `maven`, **Python** requires `python` 3.7 or above,
- For example, **Java** requires an OpenJDK 8 distribution and `maven`, **Python** requires `python` 3.8 or above,
etc...

## Code Generation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ The `python` target requires two configuration entries:
- Additionally, the following `Programming Language ::` classifiers are already set (more could be added by the user
if relevant):
- `Programming Language :: Python :: 3 :: Only`
- `Programming Language :: Python :: 3.7`
- `Programming Language :: Python :: 3.8`
- `Programming Language :: Python :: 3.9`
- `Programming Language :: Python :: 3.10`
Expand Down
2 changes: 1 addition & 1 deletion gh-pages/content/user-guides/lib-author/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ to produce releasable artifacts.
| .NET | .NET ≥ 6.0 |
| Go | Go ≥ 1.18 |
| Java | JDK ≥ 8 *and* Maven ≥ 3.6 |
| Python | Python ≥ 3.7 |
| Python | Python ≥ 3.8 |


## :octicons-desktop-download-24: Download Locations
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ exclude = '\.(git|mypy_cache|env)'
ignore_missing_imports = true

[tool.pyright]
pythonVersion = "3.7"
pythonVersion = "3.8"
venv = ".env"
venvPath = "."
3 changes: 1 addition & 2 deletions packages/@jsii/python-runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
"python-dateutil",
"typing_extensions>=3.7,<5.0",
],
python_requires="~=3.7",
python_requires="~=3.8",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: JavaScript",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
24 changes: 19 additions & 5 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,13 @@ abstract class BaseMethod implements PythonBase {
const liftedProperties = this.getLiftedProperties(context.resolver);

if (liftedProperties.length >= 1) {
// Anything before the 1st keyword argument is positional-only
if (pythonParams.length > 0) {
pythonParams.push('/'); // marks the end of positional-only arguments
}
// All of these parameters are keyword only arguments, so we'll mark them
// as such.
pythonParams.push('*');
pythonParams.push('*'); // marks the start of keyword-only arguments

// Iterate over all of our props, and reflect them into our params.
for (const prop of liftedProperties) {
Expand Down Expand Up @@ -2102,7 +2106,7 @@ class Package {
package_dir: { '': 'src' },
packages: modules.map((m) => m.pythonName),
package_data: packageData,
python_requires: '~=3.7',
python_requires: '~=3.8',
install_requires: [
`jsii${toPythonVersionRange(`^${VERSION}`)}`,
'publication>=0.0.3',
Expand All @@ -2115,7 +2119,6 @@ class Package {
'Operating System :: OS Independent',
'Programming Language :: JavaScript',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down Expand Up @@ -2236,7 +2239,7 @@ class Package {
code.line();
code.line('[tool.pyright]');
code.line('defineConstant = { DEBUG = true }');
code.line('pythonVersion = "3.7"');
code.line('pythonVersion = "3.8"');
code.line('pythonPlatform = "All"');
code.line('reportSelfClsParameterName = false');
code.closeFile('pyproject.toml');
Expand Down Expand Up @@ -3144,6 +3147,8 @@ function emitParameterTypeChecks(
const [name] = param.split(/\s*[:=#]\s*/, 1);
if (name === '*') {
return { kwargsMark: true };
} else if (name === '/') {
return { positionalOnlyEndMark: true };
} else if (name.startsWith('*')) {
return { name: name.slice(1), is_rest: true };
}
Expand All @@ -3156,7 +3161,12 @@ function emitParameterTypeChecks(
const typesVar = slugifyAsNeeded('type_hints', paramNames);

let openedBlock = false;
for (const { is_rest, kwargsMark, name } of paramInfo) {
for (const {
is_rest,
kwargsMark,
positionalOnlyEndMark,
name,
} of paramInfo) {
if (kwargsMark) {
if (!context.runtimeTypeCheckKwargs) {
// This is the keyword-args separator, we won't check keyword arguments here because the kwargs will be rolled
Expand All @@ -3166,6 +3176,10 @@ function emitParameterTypeChecks(
// Skip this (there is nothing to be checked as this is just a marker...)
continue;
}
if (positionalOnlyEndMark) {
// This is the end-of-positional-only-arguments separator, this is just a marker.
continue;
}

if (!openedBlock) {
code.openBlock('if __debug__');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading