Make serializer fields import explicit by rpkilby · Pull Request #4628 · encode/django-rest-framework (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation6 Commits2 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

rpkilby

This is a better approach to fixing the from fields import * in serializers (see #4626/#4613).

@tomchristie

@adamn adamn mentioned this pull request

Oct 26, 2016

@tomchristie

Looking good - linter failed on isort, otherwise happy with it.
Any thoughts on if there's likely gotchas with users importing private functions in fields, using the serializers.* notation that we wouldn't now support? What isn't in the import anymore that used to be, that some users might be working with?

@rpkilby

from foo import * ignores objects where the name has a leading _.

@rpkilby

See the latest commit - added a section for non-field imports that are still public API.


All of the non-field definitions:

fields.py

empty is_simple_callable get_attribute set_value to_choices_dict flatten_choices_dict iter_options get_error_detail CreateOnlyDefault CurrentUserDefault SkipField REGEX_TYPE NOT_READ_ONLY_WRITE_ONLY NOT_READ_ONLY_REQUIRED NOT_REQUIRED_DEFAULT USE_READONLYFIELD MISSING_ERROR_MESSAGE

relations.py

method_overridden Hyperlink PKOnlyObject MANY_RELATION_KWARGS

From the above, serializers currently imports:

fields.py

empty get_error_detail set_value CreateOnlyDefault SkipField

relations.py

Hyperlink PKOnlyObject

@tomchristie

Great. Anyone else got thoughts/review on this?

tomchristie

)
def test_fields(self):
msg = "Expected `fields.%s` to be imported in `serializers`"

Choose a reason for hiding this comment

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

These are great!

dodobas added a commit to nyaruka/rapidpro that referenced this pull request

Mar 5, 2018

@dodobas

2 participants

@rpkilby @tomchristie