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

Let SecretStrs be value equals #1079

Merged
merged 1 commit into from
Dec 9, 2019
Merged

Let SecretStrs be value equals #1079

merged 1 commit into from
Dec 9, 2019

Conversation

sbv-trueenergy
Copy link
Contributor

@sbv-trueenergy sbv-trueenergy commented Dec 4, 2019

Change Summary

As discussed in the issue, this PR adds a __eq__ method for SecretStr that compares the secret value such that SecretStr('a') == SecretStr('a') and SecretStr('a') != SecretStr('b')

Related issue number

#1078

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Dec 4, 2019

Codecov Report

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

@@          Coverage Diff           @@
##           master   #1079   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          20      20           
  Lines        3365    3369    +4     
  Branches      663     663           
======================================
+ Hits         3365    3369    +4
Impacted Files Coverage Δ
pydantic/types.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 fe0be5f...4352772. Read the comment docs.

@sbv-trueenergy sbv-trueenergy changed the title WIP: Let SecretStrs be value equals Let SecretStrs be value equals Dec 4, 2019
@sbv-trueenergy
Copy link
Contributor Author

I couldnt find a place that needed documentation updating but correct me if I'm wrong

pydantic/types.py Show resolved Hide resolved
@@ -1699,6 +1699,10 @@ class Foobar(BaseModel):
with pytest.warns(DeprecationWarning, match=r'`secret_str.display\(\)` is deprecated'):
assert f.empty_password.display() == ''

# Assert that SecretStr is equal to SecretStr if the secret is the same.
assert f == f.copy()
assert f != f.copy(update=dict(password='4321'))
Copy link
Member

Choose a reason for hiding this comment

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

this is fine, but please add an explicit test, e.g.:

def test_secret_str():
    assert SecretStr('123') == SecretStr('123')
    assert SecretStr('123') != SecretStr('321')
    assert SecretStr('123') != '123'
    assert SecretStr('123') is not SecretStr('123')

And the same for SecretBytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept the copy version and added these below. Ok?

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

just a tweak to separate tests.

tests/test_types.py Show resolved Hide resolved
tests/test_types.py Show resolved Hide resolved
@samuelcolvin samuelcolvin merged commit 33fee6d into pydantic:master Dec 9, 2019
@samuelcolvin
Copy link
Member

thanks a lot.

andreshndz pushed a commit to cuenca-mx/pydantic that referenced this pull request Jan 17, 2020
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
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