forked from 5monkeys/django-enumfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Define default value explicitly via __default__ attribute #3
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
Open
andreif
wants to merge
5
commits into
fcurella:enum34
Choose a base branch
from
5monkeys:forks/fcurella/enum34
base: enum34
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7cc4083
Support `--failfast` argument in run_tests
andreif c803abf
Define default value explicitly via __default__ attribute
andreif dbae879
Run tests against Django 1.9+
kjagiello ede931b
Fix for issue mentioned in #37
kjagiello f5571f8
Merge pull request #42 from kjagiello/forks/fcurella/enum34
kjagiello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
sudo: false | ||
|
||
language: python | ||
|
||
python: | ||
- 2.7 | ||
- 3.3 | ||
- 3.4 | ||
- 3.5 | ||
python: 3.5 | ||
|
||
env: | ||
- DJANGO=1.6 | ||
- DJANGO=1.7 | ||
- DJANGO=1.8 | ||
|
||
matrix: | ||
exclude: | ||
- python: 3.5 | ||
env: DJANGO=1.6 | ||
- python: 3.5 | ||
env: DJANGO=1.7 | ||
include: | ||
- python: 3.4 | ||
env: DJANGO=1.8 COVERAGE=true COVERALLS_REPO_TOKEN=LdECqqwg7eelQx9w8gvooUZCFIaCqGZCv | ||
allow_failures: | ||
- env: COVERAGE=true | ||
matrix: | ||
- ENV=py27-django15 | ||
- ENV=py27-django16 | ||
- ENV=py27-django17 | ||
- ENV=py27-django18 | ||
- ENV=py27-django19 | ||
- ENV=py27-django110 | ||
- ENV=py27-django111 | ||
- ENV=py33-django15 | ||
- ENV=py33-django16 | ||
- ENV=py33-django17 | ||
- ENV=py33-django18 | ||
- ENV=py34-django15 | ||
- ENV=py34-django16 | ||
- ENV=py34-django17 | ||
- ENV=py34-django18 | ||
- ENV=py34-django19 | ||
- ENV=py34-django110 | ||
- ENV=py34-django111 | ||
- ENV=py35-django18 | ||
- ENV=py35-django19 | ||
- ENV=py35-django110 | ||
- ENV=py35-django111 | ||
- ENV=coverage | ||
|
||
install: | ||
- pip install flake8 | ||
- pip install -q "Django>=$DJANGO,<$DJANGO.99" | ||
- make install | ||
|
||
script: | ||
- make flake8 | ||
- make test | ||
|
||
after_script: | ||
- if [ "$COVERAGE" == "true" ]; then | ||
pip install --quiet python-coveralls; | ||
make coverage; | ||
coverage report; | ||
coveralls --ignore-errors; | ||
fi | ||
- pip install tox | ||
|
||
notifications: | ||
email: | ||
- [email protected] | ||
script: tox -e $ENV |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
urlpatterns = () |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree on the ambiguity that this introduces. To quote the zen of Python "There should be one-- and preferably only one --obvious way to do it."
What bother me most is that having two ways to declare the default means I'll have to check both every time the field does not have a default declared.
Assume the following scenario: I've inherited a code-base, and I'm going through its models and I see:
Now I have to check 2 places to find out if there is a default: the field declaration above, and the enum declaration. This for every single time the
EnumField
is used withdefault
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well,
Enum
itself has only one place to set default i.e. via__default__
attribute. Previously, one would need to override.default()
method (still possible) and it was not obvious/expected that the first value is the default one. One could restore the old behaviour by subclassing Enum whenever it's needed:EnumField
on the other hand may be independent enough to override the default just if it's needed. For example, the same enum may be used in various places and who knows maybe someone will need to override the default just in one of them. I believe one expects this to be possible in a field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see any mention of
__default__
on the python docs (https://docs.python.org/3/library/enum.html)I think we should keep our
Enum
subclass as close as possible to the original, without supercharging it further with custom methods or properties and add the features we need only to the field instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the convenience of declaring
__default__
just once, but I'm not sure that's an advantage in the long run. I'd rather be explicit than save some keystrokes.Plus, I would make the argument that the
default
is a property of the field, and therefore belongs to the field declaration. Just in the same spirit asField.choices
works. TheEnum
is data, whiledefault=
is behaviour.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so one could define a custom field for certain enum in case it's used in many places. Sure, let me discuss it with my colleagues to see if everyone is happy about it and redo the commits 😄