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

Fix typing #658

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Fix typing #658

wants to merge 14 commits into from

Conversation

youtux
Copy link
Contributor

@youtux youtux commented Dec 2, 2023

Fix many mypy issues.
Notably, I replace private attributes like __scenario__, __scenario_report__, etc. with registries (WeakKeyDictionary). E.g.

# Old way

# setting value
scenario_wrapper.__scenario__ = scenario

# getting value
scenario = getattr(obj, "__scenario__", None)


# New way
# setting value
scenario_wrapper_template_registry[scenario_wrapper] = scenario

# getting value
scenario = scenario_wrapper_template_registry.get(scenario_wrapper)

Copy link

codecov bot commented Dec 2, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (8a694ff) 95.58% compared to head (51c2173) 95.49%.

Files Patch % Lines
src/pytest_bdd/generation.py 50.00% 1 Missing and 2 partials ⚠️
tests/feature/test_report.py 81.25% 3 Missing ⚠️
src/pytest_bdd/utils.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #658      +/-   ##
==========================================
- Coverage   95.58%   95.49%   -0.09%     
==========================================
  Files          49       49              
  Lines        1788     1819      +31     
  Branches      193      195       +2     
==========================================
+ Hits         1709     1737      +28     
- Misses         52       54       +2     
- Partials       27       28       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@youtux youtux requested a review from drothlis January 21, 2024 13:51
@youtux youtux marked this pull request as ready for review January 21, 2024 13:51
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

PR Type: Refactoring

PR Summary: The pull request introduces a refactoring that replaces private attributes with WeakKeyDictionary registries to manage scenarios and reports within the pytest_bdd framework. This change aims to fix typing issues and improve the handling of object lifecycles by avoiding strong reference cycles that can lead to memory leaks.

Decision: Comment

📝 Type: 'Refactoring' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Unsupported files: the diff contains files that Sourcery does not currently support during reviews.

General suggestions:

  • Ensure that the new registry-based approach is thoroughly tested, especially in scenarios with complex fixture setups and teardowns.
  • Consider adding inline comments explaining the choice of WeakKeyDictionary for future maintainers.
  • Review the changes to ensure that all references to the old attribute-based approach have been properly updated to the new registry-based approach.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@jsa34
Copy link
Collaborator

jsa34 commented Sep 22, 2024

@youtux I think mypy is happy now since we merged #698 ? If it is, perhaps we can close this?

@youtux
Copy link
Contributor Author

youtux commented Sep 22, 2024

Well, mypy is happy only because we put a lot of #type: ignore, ideally we wouldn't need those

@jsa34
Copy link
Collaborator

jsa34 commented Sep 22, 2024

Good point - so the focus of this would be to eliminate those where possible :)

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.

2 participants