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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error for in_(a_string) with a non-string value #383

Merged
merged 4 commits into from May 25, 2018

Conversation

Zac-HD
Copy link
Contributor

@Zac-HD Zac-HD commented May 23, 2018

  • Added tests for changed code.
  • Changes (and possible deprecations) have news fragments in changelog.d.
  • Is my first attrs PR 馃槏

Closes #382.

@codecov
Copy link

codecov bot commented May 23, 2018

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #383   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           9      9           
  Lines         831    835    +4     
  Branches      174    174           
=====================================
+ Hits          831    835    +4
Impacted Files Coverage 螖
src/attr/validators.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 8274c9f...1a28db0. Read the comment docs.

Copy link

@wsanchez wsanchez left a comment

Choose a reason for hiding this comment

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

Please address comments.

if value not in self.options:
try:
in_options = value in self.options
except Exception as e: # e.g. `1 in "abc"`

This comment was marked as spam.

@@ -243,6 +243,18 @@ def test_fail(self):
"'test' must be in [1, 2, 3] (got None)",
) == e.value.args

def test_fail_with_string(self):
"""
Same error for string options as for list options, not TypeError.

This comment was marked as spam.

@Zac-HD
Copy link
Contributor Author

Zac-HD commented May 24, 2018

@wsanchez - done 馃槃

@@ -0,0 +1,3 @@
``in_()`` validators now raise a ValueError with a useful message

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,2 @@
``attr.validators.in_()`` now raises a ``ValueError`` with a useful message even if the options are a string and the value is not a string.
Previously, this raised a ``TypeError`` (matching e.g. ``1 in "abc"``).

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@hynek hynek merged commit a3dbdfc into python-attrs:master May 25, 2018
@hynek
Copy link
Member

hynek commented May 25, 2018

Thanks!

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.

None yet

3 participants