Skip to content

chore: constrain Pattern type #1440

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

Merged
merged 2 commits into from
Jul 19, 2022
Merged

Conversation

rwoll
Copy link
Member

@rwoll rwoll commented Jul 18, 2022

Fixes #1415.

Most of this change was generated. The actual changed code (aside from find and replace) is in //scripts/documentation_provider.py.

NB: Using bytes in patterns with our code will currently explode, so
this constrains to hint to users to use str patterns:

# OK
await expect(page).to_have_url(re.compile(r".*/grid\.html"))
# BAD
await expect(page).to_have_url(re.compile(rb".*/grid\.html"))

This change opts to constrain the type rather than allow for bytes, too. If a user wants to use bytes, they can encode/decode explicitly.

Fixes microsoft#1415.

NB: Using bytes in patterns with our code will currently explode, so
this type constrains to hint to users to use str patterns:

```py
await expect(page).to_have_url(re.compile(r".*/grid\.html"))
await expect(page).to_have_url(re.compile(rb".*/grid\.html"))
```

This change opts to constrain the type rather than allow for bytes, too.
@rwoll rwoll requested a review from mxschmitt July 18, 2022 23:36
@rwoll rwoll requested a review from mxschmitt July 19, 2022 21:01
@rwoll rwoll merged commit c123ce0 into microsoft:main Jul 19, 2022
@KotlinIsland
Copy link

KotlinIsland commented Jul 19, 2022

Cool, just wondering why you use a custom NoneType instead of None? (unrelated to this PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] (🐞) typing.Pattern used in type hints are not supplied type parameters
3 participants