[issue45331] Can create enum of ranges, cannot create range enum. Range should be subclassable... or EnumMeta.__new__ should be smarter.

2022-01-10 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
keywords: +patch
nosy: +sobolevn
nosy_count: 2.0 -> 3.0
pull_requests: +28722
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30521

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45331] Can create enum of ranges, cannot create range enum. Range should be subclassable... or EnumMeta.__new__ should be smarter.

2022-01-10 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 6223cbf86ad7d5e6d12f9747e5a9cf1d8c72bdc8 by Nikita Sobolev in 
branch 'main':
bpo-45331: [Enum] add rule to docs that mixin type must be subclassable 
(GH-30521)
https://github.com/python/cpython/commit/6223cbf86ad7d5e6d12f9747e5a9cf1d8c72bdc8


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45331] Can create enum of ranges, cannot create range enum. Range should be subclassable... or EnumMeta.__new__ should be smarter.

2022-01-12 Thread Alex Waygood


Change by Alex Waygood :


--
components: +Documentation -Interpreter Core
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45331] Can create enum of ranges, cannot create range enum. Range should be subclassable... or EnumMeta.__new__ should be smarter.

2021-09-30 Thread Sam Bishop


New submission from Sam Bishop :

Range types are perfectly valid as values in an enum, like so.

class EnumOfRanges(Enum):
ZERO = range(0, 0)
RANGE_A = range(1, 11)
RANGE_B = range(11, 26)


However unlike the other base types , 'int', 'str', 'float', etc. You cannot 
create a "range enum" 

class RangeEnum(range, Enum):
ZERO = range(0, 0)
RANGE_A = range(1, 11)
RANGE_B = range(11, 26)

produces `TypeError: type 'range' is not an acceptable base type` when you try 
and import `RangeEnum`.

The current documentation for `enum` implicitly says this should work by not 
mentioning anything special here 
https://docs.python.org/3/library/enum.html#others

It also allows the use of range objects as value types, another implicit 
suggestion that we should be able to restrict an enum class to just range 
values like we can for other builtin class types.

Also to keep this a concise issue:
- Yes I'm aware not all of the base classes can be subclassed.
- Yes I know I that there are good reasons bool should not be subclassable.

So I'd like to suggest one of three things should be done to improve the 
situation:

A: Solve https://bugs.python.org/issue17279 and by documenting the special base 
class objects that cannot be subclassed and reference this in the documentation 
for Enums.

B: Make a decision as to which base class objects we should be able to 
subclass, and then improve their C implementations to allow subclassing. (It's 
also probably worth documenting the final list of special objects and solving 
https://bugs.python.org/issue17279 should this approach be selected.) 

C: The __new__ method on EnumMeta should be made smarter so that it either 
emits a more useful warning (I had to head to the CPython source code to work 
out what the error `TypeError: type 'range' is not an acceptable base type` 
meant) or somehow being more smart about how it handles the special classes 
which can't cannot be subclassed allowing them to be used anyway.  which again 
sort of involves solving https://bugs.python.org/issue17279, and in the case 
that its just made magically smarter, I'll admit could confuse some people as 
to why "Enum" is special and can subclass these but their own code can't just 
do `class MyRange(range):` 

Regardless of the outcome, it would be good to fill in this pitfall one way or 
the other for the sake of future developers, I'm a reasonably experienced 
Python developer and it caught me by surprise I'm likely not the first and 
probably wont be the last if the behaviour remains as it currently is.

--
components: Interpreter Core
messages: 402960
nosy: techdragon
priority: normal
severity: normal
status: open
title: Can create enum of ranges, cannot create range enum. Range should be 
subclassable... or EnumMeta.__new__ should be smarter.
type: enhancement
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45331] Can create enum of ranges, cannot create range enum. Range should be subclassable... or EnumMeta.__new__ should be smarter.

2021-09-30 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman
nosy: +ethan.furman
versions: +Python 3.11 -Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com