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

Add handling for from_regex and test for change #3550

Merged

Conversation

JensHeinrich
Copy link

Fixes #3549

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jens - for the bug report and also the patch! I think it's pretty close; just want to make sure that we've covered off any 'nearby' issues before merging 🙂

hypothesis-python/RELEASE.rst Outdated Show resolved Hide resolved
Comment on lines 588 to 589
strategy.function is st.from_type
or strategy.function.__name__ is st.from_regex.__name__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe strategy.function in (st.from_type, st.from_regex)?

We'll also want to handle more than just the first argument, in case of e.g. st.from_regex("pattern", flags=re.ASCII). If handling flags turns out to be a huge pain I'm happy to just open an issue about that for later, but it'd be good to investigate now in case we can support that with only minor changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sadly does not work, they get different memory addresses somehow, so it needs to be done via .__name__.

Probably iterating on ._LazyStrategy__kwargs and _LazyStrategy__args is the best bet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just realized the from_regex does not support flags itself, they need to be included in the pattern after the last / or in the re.compile call

hypothesis-python/tests/ghostwriter/test_ghostwriter.py Outdated Show resolved Hide resolved
@JensHeinrich
Copy link
Author

(Did a rebase)

@JensHeinrich JensHeinrich force-pushed the feature/handle-from_regex-import branch from 4c774cb to 38ee9d3 Compare February 16, 2023 17:05
@JensHeinrich
Copy link
Author

New branch and cherry picked

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thanks again for finding and fixing this!

@Zac-HD Zac-HD merged commit b3c3ebe into HypothesisWorks:master Feb 17, 2023
@JensHeinrich
Copy link
Author

Lovely, thanks again for finding and fixing this!

Well, if something annoys me and I can change it, I try to change it^^

@Zac-HD
Copy link
Member

Zac-HD commented Feb 17, 2023

❤️ open source!

@JensHeinrich JensHeinrich deleted the feature/handle-from_regex-import branch March 7, 2023 06:54
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.

Ghostwriter unaware of imports for regex strategies
2 participants