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: exit serialization early on detection of a cycle #78

Merged
merged 7 commits into from
Dec 29, 2019
Merged

Conversation

iamogbz
Copy link
Collaborator

@iamogbz iamogbz commented Dec 29, 2019

Description

Tracks visited items in serialization and exits early when cycle is encountered or max depth exceeded

Related Issues

Checklist

  • This PR has sufficient test coverage.

Additional Comments

  • Opted to not fail on cycle, since this is not necessarily an invalid data structure

@codecov
Copy link

codecov bot commented Dec 29, 2019

Codecov Report

Merging #78 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #78   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          14     14           
  Lines         527    540   +13     
=====================================
+ Hits          527    540   +13
Impacted Files Coverage Δ
src/syrupy/serializers/amber.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b173d5...a3e28c6. Read the comment docs.

@iamogbz iamogbz requested a review from noahnu December 29, 2019 01:32
@noahnu noahnu self-assigned this Dec 29, 2019
src/syrupy/serializers/amber.py Outdated Show resolved Hide resolved
src/syrupy/serializers/amber.py Outdated Show resolved Hide resolved
@@ -89,7 +92,9 @@ def object_type(cls, data: "SerializableData") -> str:
return f"<class '{data.__class__.__name__}'>"

@classmethod
def serialize_string(cls, data: "SerializableData", indent: int = 0) -> str:
def serialize_string(
cls, data: "SerializableData", *, indent: int = 0, visited: List[Any] = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can remove the unused visited kwarg if we do **_, not sure how mypy handles that though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it complained last I tried, will attempt again but treating as non blocking

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Too much refactoring needed to satisfy mypy and ignore the argument, leaving as is

src/syrupy/serializers/amber.py Outdated Show resolved Hide resolved
@iamogbz iamogbz requested a review from noahnu December 29, 2019 04:54
@noahnu noahnu merged commit 9f2f396 into master Dec 29, 2019
@noahnu noahnu deleted the max-depth branch December 29, 2019 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serializer should fail on max depth exceeded to break cycles
2 participants