Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list

On 6/16/2023 7:37 PM, dn via Python-list wrote:

On 16/06/2023 23.47, Thomas Passin via Python-list wrote:

On 6/16/2023 1:40 AM, dn via Python-list wrote:
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?




mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as 
I find myself having to use cast() in at least every other line."


(see https://gi


thub.com/python/mypy/issues/12841)


There have also been other changes to enum  in 3.11 - here is a useful 
rundown:


https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea



Sorry to hear about mypy. PyCharm has its own mechanism - if there's 
something like mypy underneath, I don't know [which].


TBH I haven't noticed any such difficulties, BUT haven't tried using 
more than a defined sub-class of Enum - and using such as a class. Thus:


class MenuOptions( Enum ):
     """ Legal menu-choices. """
     N = "NewGame"
     L = "LoadGame"
     


if __name__ == "__main__":
     n:MenuOptions = MenuOptions.N
     print( n, type( n ) )
     # MenuOptions.N 

works correctly, but strikes me as pedantry.
(any (mypy) problematic code you'd like me to try (in PyCharm) as a 
comparison? Perhaps off-list - could summarise any pertinent discoveries 
later...)



I tried messing with the enum-members, eg N:str; but realised that 
although this worked/was passed silently, the name of a member is not 
actually a string anyway. So, backed that out.



Had noted the first web.ref but deemed it unimportant (to me - as 
above). The second I had not found, and enjoyed reading (many thanks!).


«I’ll be honest, I struggled to think of concrete cases where this would 
be useful, since I don’t tend to pile additional functionality into my 
enumerations — they’re almost always just bare classes which are members 
of another class or module which provides the related functionality. But 
I think it’s good to broaden your horizons...»


The last being the same view as led me to this point, and the first, the 
motivation for this post! As said, I tend to only use enums in a fairly 
mechanistic fashion.


However, I have been playing-around with his "additional functionality". 
For example, adding the idea of a default-value if an enquiry attempts 
to use a 'key' which is not present (which seems 'natural', but equally 
goes against (my understanding of) the ethos of an enum). Next, (see 
earlier comment about having to invoke the @member-target as a function) 
was the idea that if one is using an enum as a collection of the correct 
choices/responses in a menu (per code snippet), making the member.value 
into a function* attempts to reproduce the idiom of using a dict[ionary] 
to simulate a case/select construct - which combines the idea of an 
API's constants with making a decision as to which functionality should 
be invoked.


* function here (cf "method") because unlikely to locate such 
functionality within the enum. However, am also experimenting with 
classes (cue OOP-mumblings, eg "polymorphism", "inversion", ...)


All the fun of the fair!

BTW when I reach the point of making comparisons, I expect the enum will 
be 'cheaper' in storage; but that the dict-construct will be 'faster' - 
pure speculation(!) Repeating: curious cats, etc...




From reading the references, especially the second one, it seems to me 
that these new features are mostly intended to handle weird cases 
involving subclasses of enums.  I plan to master these features by 
avoiding them - and hope I never need to understand someone else's code 
that uses them.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Enum + new in 3.11

2023-06-16 Thread dn via Python-list

On 16/06/2023 23.47, Thomas Passin via Python-list wrote:

On 6/16/2023 1:40 AM, dn via Python-list wrote:
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?




mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as I 
find myself having to use cast() in at least every other line."


(see https://gi


thub.com/python/mypy/issues/12841)


There have also been other changes to enum  in 3.11 - here is a useful 
rundown:


https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea



Sorry to hear about mypy. PyCharm has its own mechanism - if there's 
something like mypy underneath, I don't know [which].


TBH I haven't noticed any such difficulties, BUT haven't tried using 
more than a defined sub-class of Enum - and using such as a class. Thus:


class MenuOptions( Enum ):
""" Legal menu-choices. """
N = "NewGame"
L = "LoadGame"



if __name__ == "__main__":
n:MenuOptions = MenuOptions.N
print( n, type( n ) )
# MenuOptions.N 

works correctly, but strikes me as pedantry.
(any (mypy) problematic code you'd like me to try (in PyCharm) as a 
comparison? Perhaps off-list - could summarise any pertinent discoveries 
later...)



I tried messing with the enum-members, eg N:str; but realised that 
although this worked/was passed silently, the name of a member is not 
actually a string anyway. So, backed that out.



Had noted the first web.ref but deemed it unimportant (to me - as 
above). The second I had not found, and enjoyed reading (many thanks!).


«I’ll be honest, I struggled to think of concrete cases where this would 
be useful, since I don’t tend to pile additional functionality into my 
enumerations — they’re almost always just bare classes which are members 
of another class or module which provides the related functionality. But 
I think it’s good to broaden your horizons...»


The last being the same view as led me to this point, and the first, the 
motivation for this post! As said, I tend to only use enums in a fairly 
mechanistic fashion.


However, I have been playing-around with his "additional functionality". 
For example, adding the idea of a default-value if an enquiry attempts 
to use a 'key' which is not present (which seems 'natural', but equally 
goes against (my understanding of) the ethos of an enum). Next, (see 
earlier comment about having to invoke the @member-target as a function) 
was the idea that if one is using an enum as a collection of the correct 
choices/responses in a menu (per code snippet), making the member.value 
into a function* attempts to reproduce the idiom of using a dict[ionary] 
to simulate a case/select construct - which combines the idea of an 
API's constants with making a decision as to which functionality should 
be invoked.


* function here (cf "method") because unlikely to locate such 
functionality within the enum. However, am also experimenting with 
classes (cue OOP-mumblings, eg "polymorphism", "inversion", ...)


All the fun of the fair!

BTW when I reach the point of making comparisons, I expect the enum will 
be 'cheaper' in storage; but that the dict-construct will be 'faster' - 
pure speculation(!) Repeating: curious cats, etc...


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list

On 6/16/2023 1:40 AM, dn via Python-list wrote:
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?



"What's New" says:
Added the member() and nonmember() decorators, to ensure the decorated 
object is/is not converted to an enum member.


The PSL docs say:
@enum.member
     A decorator for use in enums: its target will become a member.

also:
enum members have names and values (the name of Color.RED is RED, the 
value of Color.BLUE is 3, etc.)


Whereas the "Utilities and Decorators" section is slightly confusing 
because class decorators are mixed with others, so one has to read 
more-carefully.



"Curiosity killed the cat" and other cautionary tales/tails...

Have added the following decorated staticmethod to a basic enum. It is 
indeed recognised as a member of the enum, but its value is the 
method-object. To gain the value the method-object represents 
(property-like behavior) one has to call the method/enum-value as a 
function:-



from enum import Enum, member


class MenuOptions( Enum ):
     """ Legal menu-choices. """
     N = "NewGame"
     L = "LoadGame"
     # ...

     @member
     @staticmethod
     def extra_member()->str:
     return "QuitGame"


def print_demo( enum_chosen:MenuOptions )->None:
     """ Illustrative printing. """
     print( "Name:", enum_chosen, enum_chosen.name )
     if isinstance( enum_chosen, MenuOptions ):
     print( "Value:", enum_chosen.value )


print( MenuOptions.__members__ )
# {'N': , 'L': , 
'extra_member': MenuOptions.extra_member at 0x7f0802128860>)>>}


print_demo( MenuOptions[ "L" ] )
# Name: MenuOptions.L L
# Value: LoadGame

print_demo( MenuOptions.extra_member )
# Name: MenuOptions.extra_member extra_member
# Value: 0x7f0802128860>)>


print( MenuOptions.extra_member.value() )
# QuitGame


Therefore, like an @property decorator applied to a method in a 
custom-class, it could be used to only evaluate some 'expensive' 
computation if/when it is needed. Similarly, it could use the other 
values within the enum in order to present some 'combination'.


Weirdly (given that enums are considered immutable) I imagine that if 
the 'extra_member' were to call some external function with varying 
output, the value could be considered mutable when it is eventually called.


Other?better ideas...


mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as I 
find myself having to use cast() in at least every other line."


(see https://github.com/python/mypy/issues/12841)

There have also been other changes to enum  in 3.11 - here is a useful 
rundown:


https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea

--
https://mail.python.org/mailman/listinfo/python-list


Enum + new in 3.11

2023-06-15 Thread dn via Python-list
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?



"What's New" says:
Added the member() and nonmember() decorators, to ensure the decorated 
object is/is not converted to an enum member.


The PSL docs say:
@enum.member
A decorator for use in enums: its target will become a member.

also:
enum members have names and values (the name of Color.RED is RED, the 
value of Color.BLUE is 3, etc.)


Whereas the "Utilities and Decorators" section is slightly confusing 
because class decorators are mixed with others, so one has to read 
more-carefully.



"Curiosity killed the cat" and other cautionary tales/tails...

Have added the following decorated staticmethod to a basic enum. It is 
indeed recognised as a member of the enum, but its value is the 
method-object. To gain the value the method-object represents 
(property-like behavior) one has to call the method/enum-value as a 
function:-



from enum import Enum, member


class MenuOptions( Enum ):
""" Legal menu-choices. """
N = "NewGame"
L = "LoadGame"
# ...

@member
@staticmethod
def extra_member()->str:
return "QuitGame"


def print_demo( enum_chosen:MenuOptions )->None:
""" Illustrative printing. """
print( "Name:", enum_chosen, enum_chosen.name )
if isinstance( enum_chosen, MenuOptions ):
print( "Value:", enum_chosen.value )


print( MenuOptions.__members__ )
# {'N': , 'L': , 
'extra_member': MenuOptions.extra_member at 0x7f0802128860>)>>}


print_demo( MenuOptions[ "L" ] )
# Name: MenuOptions.L L
# Value: LoadGame

print_demo( MenuOptions.extra_member )
# Name: MenuOptions.extra_member extra_member
# Value: 0x7f0802128860>)>


print( MenuOptions.extra_member.value() )
# QuitGame


Therefore, like an @property decorator applied to a method in a 
custom-class, it could be used to only evaluate some 'expensive' 
computation if/when it is needed. Similarly, it could use the other 
values within the enum in order to present some 'combination'.


Weirdly (given that enums are considered immutable) I imagine that if 
the 'extra_member' were to call some external function with varying 
output, the value could be considered mutable when it is eventually called.


Other?better ideas...

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


[issue47111] ENUM TypeError using mixing

2022-03-24 Thread Ethan Furman


Change by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

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



[issue47111] ENUM TypeError using mixing

2022-03-24 Thread Benyamin Guedj


New submission from Benyamin Guedj :

when trying to implement mixing with enum

```python
from typing import Tuple
from enum import Enum
class Blah(Tuple[str, ...], Enum):
val = ('a', 'b')
```


>>> from typing import Tuple
>>> from enum import Enum
>>> class Blah(Tuple[str, ...], Enum):
... val = ('a', 'b')
...
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\enum.py", line 
150, in __prepare__
member_type, first_enum = metacls._get_mixins_(cls, bases)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\enum.py", line 
574, in _get_mixins_
member_type = _find_data_type(bases) or object
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\enum.py", line 
562, in _find_data_type
raise TypeError('%r: too many data types: %r' % (class_name, data_types))
TypeError: 'Blah': too many data types: [, ]


note:
  the same code work on python 3.7, 3.9, 3.10



I have checked the source code of enum of 3.8

https://github.com/python/cpython/blob/3.8/Lib/enum.py

and it's not the same as the other version 

https://github.com/python/cpython/blob/3.9/Lib/enum.py

--
components: Library (Lib)
messages: 415942
nosy: benyamin621
priority: normal
severity: normal
status: open
title: ENUM TypeError using mixing
type: crash
versions: Python 3.8

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



[issue47018] ImportError: cannot import name '_simple_enum' from 'enum'

2022-03-14 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

What makes you think you are supposed to be able to import _simple_enum? It is 
a name with a leading underscore, so even if it exists, it is private and you 
shouldn't touch it.

Unless _simple_enum is documented as something you can use, this is not a bug 
and there is nothing to fix.

I don't see "_simple_enum" listed anywhere in the enum documentation, so why do 
you think you should be able to import it?

https://docs.python.org/3/library/enum.html


By the way, "reinstall Python" is almost never the solution to problems. Why do 
you think you need to "fix the install"?

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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



[issue47018] ImportError: cannot import name '_simple_enum' from 'enum'

2022-03-14 Thread AverseMoon54797


New submission from AverseMoon54797 :

Why is this happening? Is there a fix for this I can't even fix the install 
because I get this error trying to reinstall cpython.

--
messages: 415206
nosy: AverseMoon
priority: normal
severity: normal
status: open
title: ImportError: cannot import name '_simple_enum' from 'enum'

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



[issue46562] Add typeof or enum behavior in the typing module

2022-01-28 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

Thanks for your report!

I think you're looking for the Literal type.

Also, new typing behaviors are better discussed first on 
https://github.com/python/typing or the typing-sig mailing list.

--
nosy: +Jelle Zijlstra
resolution:  -> later
stage:  -> resolved
status: open -> closed
versions: +Python 3.11 -Python 3.10

___
Python tracker 

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



[issue46562] Add typeof or enum behavior in the typing module

2022-01-28 Thread Pedro Torres


Change by Pedro Torres :


--
title: Add typeof or enum behavior for in the Typing module -> Add typeof or 
enum behavior in the typing module

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



[issue46562] Add typeof or enum behavior for in the Typing module

2022-01-28 Thread Pedro Torres


Change by Pedro Torres :


--
title: Add typeof or eum behavior for in the Typing module -> Add typeof or 
enum behavior for in the Typing module

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



[issue46477] Enum: ensure bitwise operators on subclasses are correct

2022-01-22 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 353e3b2820bed38da16140276786eef9ba33d3bd by Ethan Furman in 
branch 'main':
bpo-46477: [Enum] ensure Flag subclasses have correct bitwise methods (GH-30816)
https://github.com/python/cpython/commit/353e3b2820bed38da16140276786eef9ba33d3bd


--

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



[issue46477] Enum: ensure bitwise operators on subclasses are correct

2022-01-22 Thread Ethan Furman


Change by Ethan Furman :


--
keywords: +patch
pull_requests: +29003
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30816

___
Python tracker 

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



[issue46477] Enum: ensure bitwise operators on subclasses are correct

2022-01-22 Thread Ethan Furman


New submission from Ethan Furman :

Creating one's own int Flag type doesn't work properly with regards to the 
bitwise operators:

class MyIntFlag(int, Flag):
ONE = 1
TWO = 2
FOUR = 4

MyIntFlag.ONE | MyIntFlag.TWO
# 

MyIntFlag.ONE | 2
# 3

--
assignee: ethan.furman
messages: 411319
nosy: ethan.furman
priority: normal
severity: normal
status: open
title: Enum: ensure bitwise operators on subclasses are correct
type: behavior
versions: Python 3.11

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-22 Thread Ethan Furman


Change by Ethan Furman :


--
status: open -> closed

___
Python tracker 

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



[issue43430] Exception raised when attempting to create Enum via functional API

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:

Thanks for the reminder.

--
resolution:  -> not a bug
stage:  -> resolved
status: pending -> closed

___
Python tracker 

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



[issue43430] Exception raised when attempting to create Enum via functional API

2022-01-17 Thread Irit Katriel


Irit Katriel  added the comment:

Is there a bug/documentation change to make here or can this be closed?

--
nosy: +iritkatriel
status: open -> pending
type: crash -> behavior
versions: +Python 3.10 -Python 3.7, Python 3.8

___
Python tracker 

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



[issue46108] Enum repr() incorrect when mixed with non-__new__ data types

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:

Fixed in 3.11.

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
superseder:  -> Enum: modify __repr__, __str__; update docs
type:  -> behavior

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Change by Ethan Furman :


--
priority: release blocker -> normal
resolution:  -> fixed
stage: patch review -> resolved

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 62a6594e66ca955073be2f4e5a40291a39252ef3 by Ethan Furman in 
branch 'main':
bpo-40066: [Enum] fix tests (GH-30643)
https://github.com/python/cpython/commit/62a6594e66ca955073be2f4e5a40291a39252ef3


--

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread STINNER Victor


STINNER Victor  added the comment:

I created https://github.com/python/core-workflow/issues/424 "Should we make 
the Docs CI mandatory on the Python main branch?".

--

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +28846
pull_request: https://github.com/python/cpython/pull/30643

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:

vstinner wrote:
--
>>self.assertEqual(repr(type), '')

> For this one, I suggest to replace the value with "..." doctest pattern.

That bit of code is from the unittest suite, not the doctest suite.

I went with:  

self.assertEqual(repr(type), '' % type.value)

--

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread STINNER Victor


STINNER Victor  added the comment:

>self.assertEqual(repr(type), '')

For this one, I suggest to replace the value with "..." doctest pattern.

--

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 83d544b9292870eb44f6fca37df0aa351c4ef83a by Kumar Aditya in 
branch 'main':
bpo-40066: [Enum] skip failing doc test (GH-30637)
https://github.com/python/cpython/commit/83d544b9292870eb44f6fca37df0aa351c4ef83a


--

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Ethan Furman


Ethan Furman  added the comment:

After merging in doc fix by kumaraditya303, I'll update tests so Solaris passes.

--

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Kumar Aditya


Change by Kumar Aditya :


--
nosy: +kumaraditya303
nosy_count: 15.0 -> 16.0
pull_requests: +28840
pull_request: https://github.com/python/cpython/pull/30637

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread STINNER Victor


STINNER Victor  added the comment:

Sorry, I had to revert the change since it broke the CI and it prevented to 
merge new PRs. Tell me if I can help to get this test fixed and to get this 
change merged again.

By the way, the PR 30582 was merged even if the Docs CI failed.

--

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 42a64c03ec5c443f2a5c2ee4284622f5d1f5326c by Victor Stinner in 
branch 'main':
Revert "bpo-40066:  [Enum] update str() and format() output (GH-30582)" 
(GH-30632)
https://github.com/python/cpython/commit/42a64c03ec5c443f2a5c2ee4284622f5d1f5326c


--

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread STINNER Victor


Change by STINNER Victor :


--
nosy: +vstinner
nosy_count: 14.0 -> 15.0
pull_requests: +28835
pull_request: https://github.com/python/cpython/pull/30632

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-17 Thread Jakub Kulik


Jakub Kulik  added the comment:

This also broke our Solaris build with the following error:

==
FAIL: testGetaddrinfo (test.test_socket.GeneralModuleTests)
--
Traceback (most recent call last):
  File "//cpython-main/Lib/test/test_socket.py", line 1523, in 
testGetaddrinfo
self.assertEqual(repr(type), '')
^^^
AssertionError: '' != ''
- 
?  ^
+ 
?  ^

(test.test_socket.GeneralModuleTests fails with the same error).

The issue is almost certainly that on Solaris, SOCK_STREAM is defined as 2 
rather than 1; the following simple program confirms that:

#include 
#include 

void main() {
printf("%d\n", SOCK_STREAM);
}

I'm just not sure whether to fix this with `assertRegex` or a special branch 
for Solaris (though I am not sure whether everybody else uses 1 or it's more 
varied).

--
nosy: +kulikjak

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-16 Thread Christian Heimes


Christian Heimes  added the comment:

GH-30582 broke doc tests in 3.11 branch:

File "library/enum.rst", line ?, in default
Failed example:
Color(0)
Exception raised:
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/Lib/doctest.py", line 1346, in 
__run
exec(compile(example.source, filename, "single",

  File "", line 1, in 
Color(0)
^
NameError: name 'Color' is not defined

--
nosy: +christian.heimes, pablogsal
priority: normal -> release blocker
versions: +Python 3.11

___
Python tracker 

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-15 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset acf7403f9baea3ae1119fc6b4a3298522188bf96 by Ethan Furman in 
branch 'main':
bpo-40066:  [Enum] update str() and format() output (GH-30582)
https://github.com/python/cpython/commit/acf7403f9baea3ae1119fc6b4a3298522188bf96


--

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



[issue46242] Improve error message when attempting to extend an enum with `__call__`

2022-01-14 Thread Alex Waygood


Change by Alex Waygood :


--
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



[issue46242] Improve error message when attempting to extend an enum with `__call__`

2022-01-14 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset e674e48ddc2712f28cc7ecdc66a6c328066694b0 by Nikita Sobolev in 
branch 'main':
bpo-46242: [Enum] better error message for extending `Enum` with members 
(GH-30357)
https://github.com/python/cpython/commit/e674e48ddc2712f28cc7ecdc66a6c328066694b0


--

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



[issue40066] Enum: modify __repr__, __str__; update docs

2022-01-13 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +28780
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30582

___
Python tracker 

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2022-01-13 Thread Ethan Furman


Ethan Furman  added the comment:

Ram asked:
-
> Also, aren't you excluding a lot of important magic methods from that `dir`?

Ethan replied:
-
> We decided the dunder methods were not interesting, so declined to include
> them in the listing.  And no, we are not changing our minds on that.  ;)

--

UPDATE:  We have changed our minds, but only for enums that have a data type, 
such as `int` or `str`, mixed in.  This behavior should be in 3.11.

--

___
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.

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 
<https://bugs.python.org/issue45331>
___
___
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 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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-10 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 582286d71c7ee61f5376a846a83c7be4a5727636 by Nikita Sobolev in 
branch 'main':
bpo-46301: [Enum] fix refleak tests (GH30510)
https://github.com/python/cpython/commit/582286d71c7ee61f5376a846a83c7be4a5727636


--

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-10 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
pull_requests: +28714
pull_request: https://github.com/python/cpython/pull/30510

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-09 Thread Ethan Furman


Change by Ethan Furman :


--
Removed message: https://bugs.python.org/msg410184

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-09 Thread Ethan Furman


Ethan Furman  added the comment:

Reverting.

Nikita, you can use the command:

./python -m test.regrtest -R : test_enum

to show the leaks and hopefully track them down.  The half-hour I spent yielded 
no clues.

--

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-09 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

Seems that this PR has broken the refleak buildbots:

https://buildbot.python.org/all/#/builders/320/builds/269/
https://buildbot.python.org/all/#/builders/384/builds/255

According to our buildbot policy, if this is not fixed in 24h we will need to 
revert

--
nosy: +pablogsal

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-08 Thread Ethan Furman


Change by Ethan Furman :


--
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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-08 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 8d59d2563b914b7208779834895c080c70cd94dd by Nikita Sobolev in 
branch 'main':
bpo-46301: [Enum] test uncomparable values in `_convert_` (GH-30472)
https://github.com/python/cpython/commit/8d59d2563b914b7208779834895c080c70cd94dd


--

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



[issue46242] Improve error message when attempting to extend an enum with `__call__`

2022-01-08 Thread Alex Waygood


Change by Alex Waygood :


--
assignee:  -> ethan.furman

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-07 Thread Ethan Furman


Ethan Furman  added the comment:

Alex, thanks for nosying me.  Go ahead and make Enum issues assigned to me as 
well.  :-)

--

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-07 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman

___
Python tracker 

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



[issue46301] Enum tests: One branch is not covered in `Enum._convert_`

2022-01-07 Thread Alex Waygood


Change by Alex Waygood :


--
nosy: +ethan.furman
title: One branch is not covered in `Enum._convert_` -> Enum tests: One branch 
is not covered in `Enum._convert_`

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



[issue46301] One branch is not covered in `Enum._convert_`

2022-01-07 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
keywords: +patch
pull_requests: +28675
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30472

___
Python tracker 

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



[issue46301] One branch is not covered in `Enum._convert_`

2022-01-07 Thread Nikita Sobolev


New submission from Nikita Sobolev :

This branch is never covered: 
https://github.com/python/cpython/blob/c9dc1f491e8edb0bc433cde73190a3015d226891/Lib/enum.py#L831

I will send a PR in a moment :)

--
components: Tests
messages: 410053
nosy: sobolevn
priority: normal
severity: normal
status: open
title: One branch is not covered in `Enum._convert_`
type: behavior
versions: Python 3.11

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



[issue46262] Enum tests: Error path in `_missing_()` is not covered for `Flag` and `IntFlag`

2022-01-04 Thread Ethan Furman


Change by Ethan Furman :


--
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



[issue46262] Enum tests: Error path in `_missing_()` is not covered for `Flag` and `IntFlag`

2022-01-04 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 91bc6f9615eabb10090e2e4f0fe5913885a29c8c by Nikita Sobolev in 
branch 'main':
bpo-46262: [Enum] test error path in `Flag._missing_` (GH-30408)
https://github.com/python/cpython/commit/91bc6f9615eabb10090e2e4f0fe5913885a29c8c


--

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



[issue46262] Enum tests: Error path in `_missing_()` is not covered for `Flag` and `IntFlag`

2022-01-04 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman
nosy: +ethan.furman

___
Python tracker 

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



[issue46262] Enum tests: Error path in `_missing_()` is not covered for `Flag` and `IntFlag`

2022-01-04 Thread Alex Waygood


Change by Alex Waygood :


--
title: Error path in `_missing_()` is not covered for `enum.Flag` and 
`enum.IntFlag` -> Enum tests: Error path in `_missing_()` is not covered for 
`Flag` and `IntFlag`

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



[issue46242] Improve error message when attempting to extend an enum with `__call__`

2022-01-03 Thread Alex Waygood


Change by Alex Waygood :


--
title: Improve error message when creating an enum with `__call__` -> Improve 
error message when attempting to extend an enum with `__call__`

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



[issue46242] Improve error message when creating an enum with `__call__`

2022-01-03 Thread Nikita Sobolev


Change by Nikita Sobolev :


--
keywords: +patch
pull_requests: +28571
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30357

___
Python tracker 

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



[issue46242] Improve error message when creating an enum with `__call__`

2022-01-03 Thread Nikita Sobolev

New submission from Nikita Sobolev :

Right now when creating a new `Enum`, we check not to extend `Enum` with 
existing `_member_names_`:

```python
Python 3.11.0a3+ (heads/main:8d7644fa64, Dec 30 2021, 13:00:40) [Clang 11.0.0 
(clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class A(enum.Enum):
...   a = 1
... 
>>> class B(A): pass
... 
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 398, in __prepare__
metacls._check_for_existing_members(cls, bases)
^^^
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 850, in 
_check_for_existing_members
raise TypeError(

TypeError: B: cannot extend enumeration 'A'
```

But when we try to use `A()` call to do the same, where what happens:

```
Python 3.11.0a3+ (heads/main:8d7644fa64, Dec 30 2021, 13:00:40) [Clang 11.0.0 
(clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class A(enum.Enum):
...   a = 1
... 
>>> B = A('B', 'b')
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 606, in __call__
return cls._create_(
   ^
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 770, in _create_
_, first_enum = cls._get_mixins_(class_name, bases)
^^^
  File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 899, in _get_mixins_
raise TypeError('Cannot extend enumerations')
^
TypeError: Cannot extend enumerations
```

I propose to use the first error message in this case as well. Moreover, this 
behavior is not covered with tests:

```
» ag 'Cannot extend enumerations'
Lib/enum.py
899:raise TypeError('Cannot extend enumerations')
```

I will add tests for this edge case.

--
components: Library (Lib)
messages: 409583
nosy: ethan.furman, pablogsal, sobolevn
priority: normal
severity: normal
status: open
title: Improve error message when creating an enum with `__call__`
type: behavior
versions: Python 3.10, Python 3.11

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



[issue46132] Attempting to create an enum with slots silently fails

2021-12-19 Thread Christian Heimes


Christian Heimes  added the comment:

The primary purpose of __slots__ is not to limit attribute assignment. Slots 
are useful to define types that have a smaller memory footprint than types.

You are getting the expected behavior. Enum parent class does not have 
__slots__ and therefore automatically has a __dict__. You could make an 
argument to add __slots__ to Enum, but that would be a new feature for 3.11.

--
nosy: +christian.heimes

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



[issue46132] Attempting to create an enum with slots silently fails

2021-12-19 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman

___
Python tracker 

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



[issue46132] Attempting to create an enum with slots silently fails

2021-12-19 Thread Alex Waygood


New submission from Alex Waygood :

Attempting to create an enum with __slots__ silently fails. No error is raised 
if __slots__ are specified, but the usual behaviour of __slots__ does not work 
as expected. Attributes that are not specified in __slots__ can be freely set:


>>> from enum import Enum
>>> class Color(Enum):
... __slots__ = ()
... RED = 0
... BLUE = 1
...
>>> Color.RED.foo = 'bar'
>>>


Given that enums are rather special, I didn't exactly *expect* this to work -- 
but it might be good to raise some kind of error if a user attempts to specify 
__slots__, instead of having it fail silently.

--
messages: 408898
nosy: AlexWaygood, ethan.furman
priority: normal
severity: normal
status: open
title: Attempting to create an enum with slots silently fails
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue46108] Enum repr() incorrect when mixed with non-__new__ data types

2021-12-17 Thread Ethan Furman


Ethan Furman  added the comment:

Thanks, test added.  I also updated the title.

Code updated to treat any __repr__s as affecting the display of the member 
value instead of the member itself (i.e. the "<...: %r>" portion).  if a user 
actually wants to change the member repr they can assign it when creating the 
Enum:

class Entries(Foo, Enum):
ENTRY = 1
__repr__ = Foo.__repr__

assert repr(Entries.ENTRY1) == 'Entries(a=1)'

--
title: Enum repr() incorrect when mixed with dataclasses -> Enum repr() 
incorrect when mixed with non-__new__ data types

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



[issue46108] Enum repr() incorrect when mixed with dataclasses

2021-12-16 Thread Eric V. Smith


Eric V. Smith  added the comment:

I know you know this, but here's a version without dataclasses, in case you 
want to add a test for this, too.

from enum import Enum

class Foo:
def __init__(self, a):
self.a = a
def __repr__(self):
return f'Foo(a={self.a!r})'

class Entries(Foo, Enum):
ENTRY1 = Foo(1)

repr(Entries.ENTRY1) != ''

--
nosy: +eric.smith

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



[issue46108] Enum repr() incorrect when mixed with dataclasses

2021-12-16 Thread Ethan Furman


New submission from Ethan Furman :

from dataclasses import dataclass
from enum import Enum

@dataclass
class Foo:
a: int = 0

class Entries(Foo, Enum):
ENTRY1 = Foo(1)

repr(Entries.ENTRY1) != ''

--
assignee: ethan.furman
messages: 408748
nosy: ethan.furman
priority: normal
severity: normal
status: open
title: Enum repr() incorrect when mixed with dataclasses
versions: Python 3.10, Python 3.11, Python 3.8, Python 3.9

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



[issue44016] Enum related deprecation warnings in test_httpservers and test_faulthandler

2021-12-06 Thread STINNER Victor


STINNER Victor  added the comment:

test_httpservers warnings have been fixed.

I cannot reproduce test_faulthandler warnings. I close the issue. If someone 
still gets warnnings in test_faulthandler, please provide the full command line 
to reproduce them.


commit d3b9134ebb40bdb01ff52a37515c7c96970c9a0b
Author: Shreyan Avigyan 
Date:   Tue May 4 00:57:47 2021 +0530

Remove Enum warnings from test_httpservers (GH-25844)

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

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



[issue42248] Raised exception in Enum keeping user objects alive unnecessarily

2021-11-13 Thread Ethan Furman


Change by Ethan Furman :


--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

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



[issue44559] Enum: revert to 3.9

2021-11-13 Thread Ethan Furman


Change by Ethan Furman :


--
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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-11-03 Thread Ethan Furman


Change by Ethan Furman :


--
Removed message: https://bugs.python.org/msg405650

___
Python tracker 

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-11-03 Thread Ethan Furman


Ethan Furman  added the comment:

Eric, I'm already aware of the nested class issue; what I was hoping for was 
your actual use-case?  You're pickling and sending an entire enum (and all its 
members) to another system/process?

--

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



[issue45676] Enum: improve generics support

2021-10-29 Thread Ethan Furman


Change by Ethan Furman :


--
assignee: ethan.furman
nosy: ethan.furman
priority: normal
severity: normal
status: open
title: Enum: improve generics support
type: enhancement
versions: Python 3.11

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



[issue45657] Enum behavior when values are functions

2021-10-28 Thread Ronald Pandolfi


Ronald Pandolfi  added the comment:

Ok, yeah that works. I would have thought that __members__ could be able to 
differentiate between bound methods and external functions, but that's probably 
asking too much.

Fair enough! This works so I'm happy. Closing, "not a bug"...

--
resolution:  -> not a bug
stage:  -> 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



[issue45657] Enum behavior when values are functions

2021-10-28 Thread Alex Waygood


Alex Waygood  added the comment:

It would be difficult to define methods in Enum classes if functions in the 
class namespace were automatically converted into members. You can get around 
this by wrapping your functions in `functools.partial` objects; see 
https://stackoverflow.com/questions/40338652/how-to-define-enum-values-that-are-functions.

--
nosy: +AlexWaygood, ethan.furman

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



[issue45657] Enum behavior when values are functions

2021-10-28 Thread Ronald Pandolfi


New submission from Ronald Pandolfi :

Enum members assigned values that are functions don't remember those members. 
For example:

def my_func():
...
class Test(enum.Enum):
a=1
b=my_func

Test.__members__
Out[7]: mappingproxy({'a': })
Test.b
Out[8]: 

Even though b doesn't show in __members__ it is still an attribute of the Enum.

--
messages: 405218
nosy: ronpandolfi
priority: normal
severity: normal
status: open
title: Enum behavior when values are functions
versions: Python 3.10

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-21 Thread Ethan Furman


Change by Ethan Furman :


--
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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-21 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset e628700dbf2c3376502cbb5a9bff2d58d1102e16 by Ethan Furman in 
branch '3.9':
[3.9] bpo-44174: [Enum] add name-mangling reference (GH-29128)
https://github.com/python/cpython/commit/e628700dbf2c3376502cbb5a9bff2d58d1102e16


--

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-21 Thread Eric Cousineau


Eric Cousineau  added the comment:

> I get an error with 3.8.10, but not on the main branch (3.11) [...]

Confirmed, using 3.11.0a1 (using Docker). Seems like at least the pickling is 
fixed?

> I'm confused -- your initial report talks about pickling fields, but your 
> tests are pickling the entire class... what am I missing?

Sorry about that; the original file, `enum_test.py`, was just trying to pickle 
an enum field, i.e. `DoesNotWork.a`. However, because it uses the type 
`DoesNotWork.NestedValue2`, `pickle` tries to unpackage that type, but cannot 
access it via name because `DoesNotWork.NestedValue2` is wrapped as an enum 
*field*, rather than just a normal field.

I've uploaded a new file, `enum_nested_type_test.py`, that perhaps shows the 
root cause - the `Enum` interprets the nested class as an enum field (wrapping 
it as an enum value), rather than as "just" a nested class. In contrast, it did 
not seem to wrap the function.

Does that make sense / help at all?

--
Added file: https://bugs.python.org/file50384/enum_nested_type_test.py

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-21 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +27404
pull_request: https://github.com/python/cpython/pull/29128

___
Python tracker 

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-21 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 828722aca4ccba893f6b2e8c1d41fd74fd6e208d by Ethan Furman in 
branch '3.10':
[3.10] bpo-44174: [Enum] add reference to name mangling (GH-29117)
https://github.com/python/cpython/commit/828722aca4ccba893f6b2e8c1d41fd74fd6e208d


--

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-20 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +27393
pull_request: https://github.com/python/cpython/pull/29117

___
Python tracker 

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-20 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 7c4d96103c4e16161e9aed9a584c9857d0674099 by Ethan Furman in 
branch 'main':
bpo-44174: [Enum] add reference to name mangling (GH-29116)
https://github.com/python/cpython/commit/7c4d96103c4e16161e9aed9a584c9857d0674099


--

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-20 Thread Ethan Furman


Change by Ethan Furman :


--
keywords: +patch
pull_requests: +27392
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/29116

___
Python tracker 

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



[issue44559] Enum: revert to 3.9

2021-10-20 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 2a9ab75af32b1ee9f210ae2a0718990687d0f79d by Ethan Furman in 
branch '3.10':
bpo-44559: [Enum] restore fixes lost in 3.9 reversion (GH-29114)
https://github.com/python/cpython/commit/2a9ab75af32b1ee9f210ae2a0718990687d0f79d


--

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Ethan Furman


Ethan Furman  added the comment:

I'm confused -- your initial report talks about pickling fields, but your tests 
are pickling the entire class... what am I missing?

--

___
Python tracker 

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +ethan.furman

___
Python tracker 

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Eric V. Smith


Eric V. Smith  added the comment:

I get an error with 3.8.10, but not on the main branch (3.11). I don't have 
other versions handy to test.

Removing 3.6, as it's no longer getting bug fixes, and this doesn't look like a 
security issue.

--
nosy: +eric.smith
versions:  -Python 3.6

___
Python tracker 

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Eric Cousineau


Eric Cousineau  added the comment:

Thinking on it some more, I the current `Enum` metaclass doesn't distinguish 
between nested class and normal field, so it wraps it, thus why `pickle` gets 
confused.

Perhaps it's possible to recognize this case - the class w/ `__qualname__` can 
be checked to see if it's nested.

If so, then options are (a) skip wrapping the field, (b) failing fast, or (c) 
"no fix"?

--

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



[issue44559] Enum: revert to 3.9

2021-10-20 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +27385
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29114

___
Python tracker 

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Eric Cousineau


Eric Cousineau  added the comment:

Ah, forgot to include error message:

```



E
...
_pickle.PicklingError: Can't pickle : it's not the same object as 
__main__.DoesNotWork.NestedValue2
```

--

___
Python tracker 

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



[issue42517] Enum: do not convert private names into members

2021-10-20 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset 9733c9651afad84ab2f010e9e68b7c03976ea9f3 by Ethan Furman in 
branch '3.9':
[3.9] bpo-42517: [ENUM] update docs for changes coming in 3.11 (GH-29113)
https://github.com/python/cpython/commit/9733c9651afad84ab2f010e9e68b7c03976ea9f3


--

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



[issue45546] Unable to pickle enum with nested frozen dataclass?

2021-10-20 Thread Eric Cousineau


New submission from Eric Cousineau :

I seem cannot pickle enum values from an enum class w/ a nested frozen 
dataclass.

I can pickle a field from a normal class w/ a nested frozen dataclass, and I 
can pickle a field from an enum with a top-level frozen dataclass - perhaps 
it's some interplay with `__qualname__` and `enum.py`?.

See attached file for sample test.
I checked on 3.6.9, 3.9.7, and 3.10.0.

Looked around, couldn't easily find existing issue for this.

--
components: Library (Lib)
files: enum_test.py
messages: 404539
nosy: Eric Cousineau
priority: normal
severity: normal
status: open
title: Unable to pickle enum with nested frozen dataclass?
type: behavior
versions: Python 3.10, Python 3.6, Python 3.9
Added file: https://bugs.python.org/file50378/enum_test.py

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



[issue42517] Enum: do not convert private names into members

2021-10-20 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +27380
pull_request: https://github.com/python/cpython/pull/29113

___
Python tracker 

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-20 Thread Ethan Furman


Ethan Furman  added the comment:

It has been moved to the tutorial (links are at the top of the Enum page).

--

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



[issue44174] Unclear meaning of _Private__names in enum docs.

2021-10-20 Thread Joseph Riddle


Joseph Riddle  added the comment:

_Private__names seems to no longer exist in the Python 3.11 documentation.

https://docs.python.org/3.11/library/enum.html#private-names

It appears to have been removed in this PR 
https://github.com/python/cpython/pull/23748/files

Should this issue be updated to remove Python 3.11 from the Versions?

--
nosy: +joeriddles

___
Python tracker 

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



[issue45493] str() and repr() of enum different in Python 3.11 from Python <= 3.10

2021-10-19 Thread Barry A. Warsaw


Barry A. Warsaw  added the comment:

I can see why Ethan might be overwhelmed by reverting this change.  I tried to 
merge in his branch but failed, so I'm chucking that work and will try again.

--

___
Python tracker 

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



[issue45493] str() and repr() of enum different in Python 3.11 from Python <= 3.10

2021-10-19 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

We just need https://github.com/python/cpython/pull/27010 to be done on main to 
roll it back.

str and repr changes are quite painful to foist upon users existing code and 
tests.

--
nosy: +gregory.p.smith

___
Python tracker 

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



[issue45493] str() and repr() of enum different in Python 3.11 from Python <= 3.10

2021-10-18 Thread Ethan Furman


Ethan Furman  added the comment:

Enum was reverted at the last minute for 3.10.  I would like to keep the 
changes in 3.11 so they get more exposure.

I have asked the SC a few times for thoughts about PEP 663, including whether 
an information PEP needs formal approval, but still haven't heard back.

At any rate, I do not have the band-width to undo and then redo all the changes 
in the 3.11 Enum.

--

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



[issue45493] str() and repr() of enum different in Python 3.11 from Python <= 3.10

2021-10-18 Thread Barry A. Warsaw


Barry A. Warsaw  added the comment:

This doesn't seem right, given that PEP 663 has not been approved by the SC yet:

3.9.7 (default, Oct 13 2021, 06:45:31) 
[Clang 13.0.0 (clang-1300.0.29.3)]
ABC.a ABC.b ABC.c ABC.a 
|main=|@presto[~/projects/python/cpython:1058]% python3.10 /tmp/foo.py 
3.10.0 (default, Oct 13 2021, 06:45:00) [Clang 13.0.0 (clang-1300.0.29.3)]
ABC.a ABC.b ABC.c ABC.a 
|main=|@presto[~/projects/python/cpython:1059]% ./python.exe /tmp/foo.py 
3.11.0a1+ (heads/main:6a533a4238, Oct 18 2021, 15:30:20) [Clang 13.0.0 
(clang-1300.0.29.3)]
a b c a ABC.a

In 3.10, the behavior was reverted back to 3.9, so it makes sense that those 
two have the same output.  Python 3.11 should as well, for now at least, until 
the SC approves PEP 663

--
nosy: +barry, ethan.furman

___
Python tracker 

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



[issue45493] str() and repr() of enum different in Python 3.11 from Python <= 3.10

2021-10-16 Thread Dutcho


Dutcho  added the comment:

perhaps related to https://bugs.python.org/issue44559 ?

--

___
Python tracker 

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



  1   2   3   4   5   6   7   8   9   10   >