#2742 Allow priorities and milestones to be 0 or -1
Merged by pingou. Opened by pingou.
fix_priority_milestone  into  master

Download 2742.patch

Up until now priorities could not be 0 or -1, not 0 because we weren't
explicitly when doing if issue.priority and not -1 because it was
a reserved value that meant to say: neither a value nor None.

With this change, the default value is a random object which allows us
to set the value to anything we like including None (which means
resetting the priority).

Fixes https://pagure.io/pagure/issue/2482
Fixes https://pagure.io/pagure/issue/1888

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto 547be640d51a3fb49037868c36e9977ada3355f7

/me remembers something from 2 years ago. I wrote 'none' and you asked me if i meant 'None' :D (I was right :p)

Looks like this needs to be rebased.

rebased onto 8a8f894ec2c63c9d4e2120b7d758d27166042ebb

Rebased, how does it look now? :)

I recommend documenting these new parameters and their types in the docblock.

I think this is an OK way to do this, but I might suggest using a different name than NoneObject since it's a little confusing since it is distinct from None but has a very similar name (and technically, None is also an object.) I suggest "Unspecified" rather than NoneObject.

However, by my reading of your commit message, it seems that the intention is for the default here to indicate that nothing was passed, where passing None indicates that the user wants to reset to the default. Is it possible to reverse this, or would that be backwards-incompatible? If possible to reverse, I would suggest allowing the real None to be the default, and to have the value 'RESET' mean that the user wants to go back to defaults.

In any case, I'm not objecting to what you have here if you prefer it.

Is there a test for reseting back to the default (i.e., what passing None would do right now, outside of my suggestions)? If not, I suggest testing that as well.

LGTM!

The issue with hardcoding a value such as RESET is that I fear I would end up in the same situation that I was trying to fix here, there would be a value for which this code wouldn't work. If for some reasons someone creates a close_status RESET we wouldn't be able to reset that field anymore. Thus the use of this custom NoneObject (btw, None in python isn't really an object iirc).

Will do :)

There is already a test for resetting the priority with '' at: https://pagure.io/pagure/pull-request/2742#_5,106

But I've one ready here for None as well.

I'll push it once we finished our discussion on the use of the NoneObject :)

None is an object:

>>> None.__class__.__class__.__bases__
(<type 'object'>,)

The docs also call it an object:

https://docs.python.org/2/c-api/none.html

rebased onto 74fd1654e46ad0a008ad45d5fa58379e020da1a6

None is an object:

None.class.class.bases
(,)

Ok, but it's a singleton so a very specific type of object.

Renaming to Unspecified would work for you I believe, I'm ok with that, will do that :)

1 new commit added

  • Rename the NoneObject to Unspecified

Adjusted :)

How about something like "Used to indicate that the caller has not made a choice for a particular argument".

LGTM!

rebased onto 138ab4df826322f19d225eea8c1c7c0d732b71d5

Docstring adjusted.

Thanks for the review and feedback!

Pull-Request has been merged by pingou

Metadata