Skip to content

Bug: API Gateway - invalid escape sequence '\[' #2980

Closed

Description

@nejcskofic

Expected Behaviour

When importing from aws_lambda_powertools.event_handler.api_gateway there should be no warning raised.

Current Behaviour

Deprecation warning is raised on import on api_gateway.pyL46:

DeprecationWarning: invalid escape sequence '\['
_UNSAFE_URI = "%<> \[\]{}|^"  # noqa: W605

If pytest is run with warnings as errors, Syntax error is raised instead and module loading is terminated.

Code snippet

import warnings


def test_api_gateway_import():
    with warnings.catch_warnings():
        warnings.simplefilter("error")
        from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver

Possible Solution

Remove # noqa: W605 and prefix pattern with raw string modifier. I haven't checked if this is an issue elsewhere in the codebase.

Steps to Reproduce

  1. Remove __pycache__ from aws_lambda_powertools/event_handler (once code is bytecompiled error is no longer triggered)
  2. Run above code snippet as pytest test

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

PyPi

Debugging logs

No response

Activity

  1. added
    bug
    triage
    on Aug 21, 2023
  2. boring-cyborg commented on Aug 21, 2023

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

  3. rubenfonseca commented on Aug 21, 2023

    @rubenfonseca
    Contributor

    Looking at this now

  4. self-assigned this
    on Aug 21, 2023
  5. rubenfonseca commented on Aug 21, 2023

    @rubenfonseca
    Contributor

    Thank you so much for the very very clear explanation of the problem, and the steps to reproduce! I'm opening a PR in a few minutes.

  6. rubenfonseca commented on Aug 21, 2023

    @rubenfonseca
    Contributor

    @nejcskofic I've opened a PR to fix this, can you take a look to see if it makes sense?

  7. moved this from Triage to Working on it in Powertools for AWS Lambda (Python)on Aug 21, 2023
  8. added and removed
    triage
    on Aug 21, 2023
  9. github-actions commented on Aug 21, 2023

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    This issue is now closed. Please be mindful that future comments are hard for our team to see.

    If you need more assistance, please either tag a team member or open a new issue that references this one.

    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  10. added
    pending-release
    on Aug 21, 2023
  11. nejcskofic commented on Aug 21, 2023

    @nejcskofic
    ContributorAuthor

    @rubenfonseca Looks good, thank you for the quick response!

  12. github-actions commented on Aug 25, 2023

    @github-actions
    Contributor

    This is now released under 2.23.1 version!

  13. removed
    pending-release
    on Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugevent_handlers

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions