[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-09-16 Thread Ethan Furman


Ethan Furman  added the comment:

There was an effort to make it so `_generate_next_value_` could be defined last 
and still work correctly -- unfortunately, it could not handle the more common 
case of using `auto()` with the default `_generate_next_value_`:

  class I(Enum):
  first = auto()
  second = first + 2# this line would fail

Closing the ticket.  Thank you everyone!

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-09-16 Thread miss-islington


Change by miss-islington :


--
pull_requests: +21338
pull_request: https://github.com/python/cpython/pull/22287

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-09-16 Thread miss-islington


Change by miss-islington :


--
pull_requests: +21339
pull_request: https://github.com/python/cpython/pull/22286

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-09-16 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +21337
pull_request: https://github.com/python/cpython/pull/22285

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-09-16 Thread Ethan Furman


Change by Ethan Furman :


--
pull_requests: +21336
pull_request: https://github.com/python/cpython/pull/22284

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-06-21 Thread Ethan Furman


Ethan Furman  added the comment:

Not yet.  I want to investigate the idea Ankesh Saha had some more.

--
versions: +Python 3.10 -Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-06-21 Thread శ్రీనివాస్ రెడ్డి తాటిపర్తి

Srinivas  Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) 
 added the comment:

We can close this?

--
nosy: +thatiparthy

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-06-11 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset ebd44003c9e206755e5e28716242ed8941495a62 by Miss Islington (bot) 
in branch '3.7':
bpo-40025: Require _generate_next_value_ to be defined before members (GH-19762)
https://github.com/python/cpython/commit/ebd44003c9e206755e5e28716242ed8941495a62


--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-05-27 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset b5ecbf02e4dbdea6d1c9a6d7189137f76e70c073 by Miss Islington (bot) 
in branch '3.8':
bpo-40025: Require _generate_next_value_ to be defined before members(GH-19763)
https://github.com/python/cpython/commit/b5ecbf02e4dbdea6d1c9a6d7189137f76e70c073


--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-05-04 Thread hongweipeng


Change by hongweipeng :


--
nosy: +hongweipeng
nosy_count: 9.0 -> 10.0
pull_requests: +19219
pull_request: https://github.com/python/cpython/pull/19904

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-04-28 Thread miss-islington


Change by miss-islington :


--
pull_requests: +19084
pull_request: https://github.com/python/cpython/pull/19763

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-04-28 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 8.0 -> 9.0
pull_requests: +19083
pull_request: https://github.com/python/cpython/pull/19762

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-04-28 Thread Ethan Furman


Ethan Furman  added the comment:


New changeset d9a43e20facdf4ad10186f820601c6580e1baa80 by Ethan Onstott in 
branch 'master':
bpo-40025: Require _generate_next_value_ to be defined before members (GH-19098)
https://github.com/python/cpython/commit/d9a43e20facdf4ad10186f820601c6580e1baa80


--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-04-28 Thread Ethan Onstott


Ethan Onstott  added the comment:

Ankesh, that is the expected behavior as no patch has been merged yet.

--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-30 Thread Ankesh Saha


Ankesh Saha  added the comment:

Hi,

I have ran the code with with _generate_next_value_ method at the bottom of the 
class and didn't run into any exceptions. Please refer my python file. Please 
let me know if I am missing something.

from enum import Enum, auto

class E(Enum):
A = auto()
B = auto()
def _generate_next_value_(name, *args):
return name

for l in (E):
print(l.name)
print(l.value)

--
nosy: +ankeshsaha
Added file: https://bugs.python.org/file49014/Issue40025.PNG

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-24 Thread Jonathan Hsu


Jonathan Hsu  added the comment:

Thank you for the explanation.

--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-21 Thread Ethan Furman


Ethan Furman  added the comment:

Jonathan Hsu, you are correct -- and "don't do that" was my initial response; 
but Enum takes many pains to make sure the user doesn't shoot themselves in the 
foot, so raising a TypeError is appropriate instead of silently doing the wrong 
thing.

--

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-21 Thread Jonathan Hsu


Jonathan Hsu  added the comment:

While the current behavior may be initially unexpected, it does match the way 
that python normally behaves when defining class variables. For example, the 
following class will throw an exception because the function number_two() is 
called before it is defined:


class Numbers:
one = 1
two = number_two()

def number_two():
return 2

# NameError: name 'number_two' is not defined


However, this version is fine:


class Numbers:
one = 1

def number_two():
return 2

two = number_two()

--
nosy: +Jonathan Hsu

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-20 Thread Ethan Onstott


Change by Ethan Onstott :


--
keywords: +patch
nosy: +Ethan Onstott
nosy_count: 5.0 -> 6.0
pull_requests: +18458
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/19098

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-20 Thread Ethan Furman


Ethan Furman  added the comment:

Immediate solution is to raise an exception if `_generate_next_value_` is 
defined after members.

Possible future solution is to save all member definitions until after class is 
defined.

The exception-raising solution would require a check in `_EnumDict` where 
`_generate_next_value_` is saved -- if any members already exist, raise.

--
assignee: docs@python -> ethan.furman
keywords: +easy
stage:  -> needs patch
versions: +Python 3.8, Python 3.9

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-20 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +barry, eli.bendersky, ethan.furman

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-20 Thread Luis E.


Change by Luis E. :


--
components:  -Documentation

___
Python tracker 

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



[issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()

2020-03-20 Thread Luis E.


New submission from Luis E. :

I ran into this issue when attempting to add a custom _generate_next_value_ 
method to an existing Enum. Adding the method definition to the bottom of the 
class causes it to not be called at all:

from enum import Enum, auto

class E(Enum):
A = auto()
B = auto()
def _generate_next_value_(name, *args):
return name


E.B.value  # Returns 2, E._generate_next_value_ is not called

class F(Enum):
def _generate_next_value_(name, *args):
return name
A = auto()
B = auto()


F.B.value  # Returns 'B', as intended


I do not believe that the order of method/attribute definition should affect 
the behavior of the class, or at least it should be mentioned in the 
documentation.

--
assignee: docs@python
components: Documentation, Library (Lib)
messages: 364665
nosy: docs@python, edd07
priority: normal
severity: normal
status: open
title: enum: _generate_next_value_ is not called if its definition occurs after 
calls to auto()
type: behavior
versions: Python 3.7

___
Python tracker 

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