-
Notifications
You must be signed in to change notification settings - Fork 246
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
Python aws-cdk-lib: Invalid escape characters #4532
Comments
Thank you for your report. Can you provide some code snippets or repository that we can repro in our account? |
With the troublesome Python install, it's as simple as an The traceback we're seeing (from a pytest runner, hence the import indirection) is:
|
Thank you for the report. I'll bring this up and discuss this with the core team. |
After more chasing, I think whether this issue coming up depends on exactly how Python and tools around it are treating warnings - simply using I've created an example repo: https://github.com/DFEvans/cdk_invalid_char It contains a single Github action, which fails with the above stack trace when trying to run a file which contains:
Apologies that there's still a bit of Poetry/Pytest stuff around the problem - I've not been able to pin down the specific set of warning commands that would get a plain |
NOTE: Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import aws_cdk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\git\cdk-utils\.venv\Lib\site-packages\aws_cdk\__init__.py", line 33241, in <module>
from . import aws_apigateway
File "C:\git\cdk-utils\.venv\Lib\site-packages\aws_cdk\aws_apigateway\__init__.py", line 1742, in <module>
from ..aws_certificatemanager import ICertificate as _ICertificate_c194c70b
File "C:\git\cdk-utils\.venv\Lib\site-packages\aws_cdk\aws_certificatemanager\__init__.py", line 227, in <module>
from ..aws_cloudwatch import (
File "C:\git\cdk-utils\.venv\Lib\site-packages\aws_cdk\aws_cloudwatch\__init__.py", line 1
'''
^^^
SyntaxError: invalid escape sequence '\|' NOTE: make sure to delete a |
This seems to be caused by the generated code that puts the documentation at the top of the module (so maybe this is really a jsii issue?). The fix seems to be as simple as putting an |
@pahud, any word on this issue? |
I'm getting similar warnings with Python 3.12, aws-cdk 2.117.0.
|
I've run into this issue on python 3.11, aws-cdk-lib 2.138.0. Notably, if I install aws-cdk-lib with poetry, then run If I then run Is there any plan to fix this? |
moving to jsii |
this is a tough one. it's not as simple as treating the entire string as a raw string in jsii (i.e. |
Fixes #4532. Succinctly, the issue is that the README is copied over into the `__init__.py` file as a python comment. And then python warns that things like `\|` and `\'`, which while not often, do organically and correctly show up in markdown syntax, are invalid escapes. Some people who have set their python config to error on warnings end up erroring on this. The solution is to mark the README string as a raw string `r'''` so python does not try to register the escapes. I'm not sure how to test this in code in this PR. I have done the following to make sure that this works: I copied the repro repo from #4532 [here](https://github.com/kaizencc/cdk_invalid_char/blob/main) and got it to show the warning locally. then, I updated the actual file manually from `'''` to `r'''` and got `pytest -W error` to give me a thumbs up. So that shows that changing `'''` to `r'''` does not expect the escaped characters to be valid. I tested my local jsii-pacmak by using it to package a module in `aws-cdk`, and unzipped the python package and confirmed that the `r'''` raw string indicator shows up for the README string in `__init__.py`, and nothing else. These two combined confirms for me that this solution will work. Again I'm not sure of the best way to test that in jsii-pacmak. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
In the Python bindings, the docstring on
aws_cdk.aws_secretsmanager.__init__
contains the text:[...] If none are defined then the following set is used: `% +~`#$&*()|[]{}:;<>?!'/@"\`.
At the end of this line, the backslash-backtick sequence is interpreted by Python as an invalid escape character.
Expected Behavior
The code does not contain invalid escape sequences.
Current Behavior
The code contains an invalid escape sequence, which causes a warning. This is raising a SyntaxError for a specific Python install we have (3.10.9, potentially a vendorised version - proving difficult to track down exactly why only one install is causing trouble!).
Reproduction Steps
Import CDK in Python - check for warnings or errors related to escape sequences.
Possible Solution
It appears the docstring is taken from the Markdown at:
https://github.com/aws/aws-cdk/blob/52edf299a42f17254da0151bb939bcb303d0e5e6/packages/%40aws-cdk/aws-secretsmanager/README.md
In Python alone, replacing
\
with\\
would be the fix, but a multi-language solution is presumably more complex!Additional Information/Context
No response
CDK CLI Version
2.68.0 (build 25fda51)
Framework Version
No response
Node.js Version
v18.9.0
OS
Ubuntu
Language
Python
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: