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 a frozenset type annotation to allowed_schemes on stricturl #2198

Merged
merged 3 commits into from
Feb 11, 2021

Conversation

Midnighter
Copy link
Contributor

@Midnighter Midnighter commented Dec 12, 2020

Change Summary

I was recently using the stricturl field type and declared some constants for the allowed schemes. Semantically, it makes the most sense to me to use frozensets for those constants. Thus I propose to extend the type annotation to include FrozenSet[str].

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)

Locally, the test suite fails for me with

pydantic/main.py:367:5: C901 'BaseModel.__setattr__' is too complex (15)

but that's unrelated to my change.

@codecov
Copy link

codecov bot commented Dec 12, 2020

Codecov Report

Merging #2198 (6123b55) into master (13a5c7d) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2198   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         4199      4199           
  Branches       854       854           
=========================================
  Hits          4199      4199           
Impacted Files Coverage Δ
pydantic/networks.py 100.00% <100.00%> (ø)

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 13a5c7d...6123b55. Read the comment docs.

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

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

LGTM!
For the local error on make lint, it's because you must be using python 3.7- version.
The check is done on the line with the decorator (l367) whereas with python 3.8+ it's the decorated one that is (l368)
https://github.com/samuelcolvin/pydantic/blob/1a2791d4223ff1d18400432ef5d020ce6910aa4a/pydantic/main.py#L367-L368
We could probably just add a second # noqa: C901 on l367 like it's done above
https://github.com/samuelcolvin/pydantic/blob/1a2791d4223ff1d18400432ef5d020ce6910aa4a/pydantic/main.py#L211-L212

@Midnighter
Copy link
Contributor Author

You are correct. I had messed up something with my virtualenvs. Tests all pass in a fresh new 3.8 environment.

@samuelcolvin
Copy link
Member

LGTM, please add a change description.

@Midnighter
Copy link
Contributor Author

LGTM, please add a change description.

Sorry, I already had this locally but failed to push it. It's in now.

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

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

LGTM!

@samuelcolvin samuelcolvin merged commit a1ac464 into pydantic:master Feb 11, 2021
@samuelcolvin
Copy link
Member

thanks a lot.

@Midnighter Midnighter deleted the annotate-allowed-schemes branch February 11, 2021 18:42
PrettyWood added a commit to PrettyWood/pydantic that referenced this pull request Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants