Re: [Python-Dev] PEP487: Simpler customization of class creation

2016-07-29 Thread Martin Teichmann
Hello,

there has been quite some discussion on why PEP 487's
__init_subclass__  initializes subclasses, and not the class itself. I
think the most important details have been already thoroughly
discussed here.

One thing I was missing in the discussion is practical examples. I
have been using PEP 487-like metaclasses since several years now, and
I have never come across an application where it would have even been
nice to initialize the class itself. Also, while researching other
people's code when I wrote PEP 487, I couldn't find any such code
elsewhere, yet I found a lot of code where people took the wildest
measure to prevent a metaclass in doing its job on the first class it
is used for. One example is enum.EnumMeta, which contains code not to
make enum.Enum an enum (I do not try to propose that the enum module
should use PEP 487, it's way to complicated for that).

So once we have a practical example, we could start discussing how to
mitigate the problem.

Btw, everyone is still invited to review the patch for PEP 487 at
http://bugs.python.org/issue27366. Many thanks to Nick who already
reviewed, and also to Guido who left helpful comments!

Greetings

Martin
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP487: Simpler customization of class creation

2016-07-29 Thread Sylvain Corlay
In the traitlets library I mentioned earlier, we do have a need for this.
The corresponding function is called `setup_class`.

What it does is setting some class attributes that are required for certain
types of descriptors to be able to initialize themselves.

class MetaHasTraits(MetaHasDescriptors):

"""A metaclass for HasTraits."""
def setup_class(cls, classdict):
cls._trait_default_generators = {}
super(MetaHasTraits, cls).setup_class(classdict)


Sylvain

On Fri, Jul 29, 2016 at 5:01 PM, Martin Teichmann 
wrote:

> Hello,
>
> there has been quite some discussion on why PEP 487's
> __init_subclass__  initializes subclasses, and not the class itself. I
> think the most important details have been already thoroughly
> discussed here.
>
> One thing I was missing in the discussion is practical examples. I
> have been using PEP 487-like metaclasses since several years now, and
> I have never come across an application where it would have even been
> nice to initialize the class itself. Also, while researching other
> people's code when I wrote PEP 487, I couldn't find any such code
> elsewhere, yet I found a lot of code where people took the wildest
> measure to prevent a metaclass in doing its job on the first class it
> is used for. One example is enum.EnumMeta, which contains code not to
> make enum.Enum an enum (I do not try to propose that the enum module
> should use PEP 487, it's way to complicated for that).
>
> So once we have a practical example, we could start discussing how to
> mitigate the problem.
>
> Btw, everyone is still invited to review the patch for PEP 487 at
> http://bugs.python.org/issue27366. Many thanks to Nick who already
> reviewed, and also to Guido who left helpful comments!
>
> Greetings
>
> Martin
> ___
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/sylvain.corlay%40gmail.com
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Summary of Python tracker Issues

2016-07-29 Thread Python tracker

ACTIVITY SUMMARY (2016-07-22 - 2016-07-29)
Python tracker at http://bugs.python.org/

To view or respond to any of the issues listed below, click on the issue.
Do NOT respond to this message.

Issues counts and deltas:
  open5588 ( +2)
  closed 33818 (+56)
  total  39406 (+58)

Open issues with patches: 2442 


Issues opened (41)
==

#24773: Implement PEP 495 (Local Time Disambiguation)
http://bugs.python.org/issue24773  reopened by martin.panter

#27593: Deprecate sys._mercurial and create sys._git
http://bugs.python.org/issue27593  opened by brett.cannon

#27594: Assertion failure when running "test_ast" tests with coverage.
http://bugs.python.org/issue27594  opened by ap

#27595: Document PEP 495 (Local Time Disambiguation) features
http://bugs.python.org/issue27595  opened by belopolsky

#27596: Build failure with Xcode 8 beta on OSX 10.11
http://bugs.python.org/issue27596  opened by ronaldoussoren

#27597: Add usage examples for TracebackException, StackSummary and Fr
http://bugs.python.org/issue27597  opened by cool-RR

#27598: Add SizedIterable to collections.abc and typing
http://bugs.python.org/issue27598  opened by brett.cannon

#27599: Buffer overrun in binascii
http://bugs.python.org/issue27599  opened by serhiy.storchaka

#27602: Enable py launcher to launch repository Python.
http://bugs.python.org/issue27602  opened by terry.reedy

#27603: Migrate IDLE context menu items to shell extension
http://bugs.python.org/issue27603  opened by steve.dower

#27604: More details about `-O` flag
http://bugs.python.org/issue27604  opened by cool-RR

#27605: Inconsistent calls to __eq__ from built-in __contains__
http://bugs.python.org/issue27605  opened by vfaronov

#27606: Android cross-built for armv5te with clang and '-mthumb' crash
http://bugs.python.org/issue27606  opened by xdegaye

#27607: Importing the main module twice leads to two incompatible inst
http://bugs.python.org/issue27607  opened by SylvieLorxu

#27609: IDLE completions: format, factor, and fix
http://bugs.python.org/issue27609  opened by terry.reedy

#27611: test_tix cannot import _default_root after test_idle
http://bugs.python.org/issue27611  opened by martin.panter

#27612: socket.gethostbyname resolving octal IP addresses incorrectly
http://bugs.python.org/issue27612  opened by mattrobenolt

#27613: Empty iterator is rendered as a single bracket ] when using js
http://bugs.python.org/issue27613  opened by altvod

#27614: Race in test_docxmlrpc.py
http://bugs.python.org/issue27614  opened by earl.chew

#27618: docs for threading.Lock claim it's a class (since 3.3), but it
http://bugs.python.org/issue27618  opened by gvanrossum

#27619: getopt should strip whitespace from long arguments
http://bugs.python.org/issue27619  opened by steven.daprano

#27620: IDLE: Add keyboard equivalents for mouse actions.
http://bugs.python.org/issue27620  opened by terry.reedy

#27621: Finish IDLE Query dialog appearance and behavior.
http://bugs.python.org/issue27621  opened by serhiy.storchaka

#27623: int.to_bytes() and int.from_bytes(): raise ValueError when byt
http://bugs.python.org/issue27623  opened by mmarkk

#27627: clang fails to build ctypes on Android armv7
http://bugs.python.org/issue27627  opened by xdegaye

#27628: ipaddress incompatibility with ipaddr: __contains__ between ne
http://bugs.python.org/issue27628  opened by lukasz.langa

#27629: Cannot create ssl.SSLSocket without existing socket
http://bugs.python.org/issue27629  opened by nemunaire

#27630: Generator._encoded_EMTPY misspelling in email package
http://bugs.python.org/issue27630  opened by martin.panter

#27632: build on AIX fails when builddir != srcdir, more than bad path
http://bugs.python.org/issue27632  opened by Michael.Felt

#27635: pickle documentation says that unpickling may not call __new__
http://bugs.python.org/issue27635  opened by july

#27636: Refactor IDLE htest
http://bugs.python.org/issue27636  opened by terry.reedy

#27637: int.to_bytes(-1, ...) should automatically choose required cou
http://bugs.python.org/issue27637  opened by mmarkk

#27638: int.to_bytes() and int.from_bytes() should support 'net' and '
http://bugs.python.org/issue27638  opened by mmarkk

#27639: UserList.__getitem__ doesn't account for slices
http://bugs.python.org/issue27639  opened by staticshock

#27640: add the '--disable-test-suite' option to configure
http://bugs.python.org/issue27640  opened by xdegaye

#27641: Do not build Programs/_freeze_importlib when cross-compiling
http://bugs.python.org/issue27641  opened by thomas.perl

#27643: test_ctypes fails on AIX with xlc
http://bugs.python.org/issue27643  opened by Michael.Felt

#27644: Expand documentation about type aliases and NewType in the typ
http://bugs.python.org/issue27644  opened by michael0x2a

#27645: Supporting native backup facility of SQLite
http://bugs.python.org/issue27645  opened by lelit

#27646: yield from expression can be any iterable
http://bugs.python.org/issue27646  opened by ter

Re: [Python-Dev] PEP487: Simpler customization of class creation

2016-07-29 Thread Martin Teichmann
Hi Sylvain,

thanks for the example, it's a great example to illustrate PEP 487 and
its design decisions.

> What it does is setting some class attributes that are required for certain
> types of descriptors to be able to initialize themselves.
>
> class MetaHasTraits(MetaHasDescriptors):
>
> """A metaclass for HasTraits."""
> def setup_class(cls, classdict):
> cls._trait_default_generators = {}
> super(MetaHasTraits, cls).setup_class(classdict)

While in a metaclass solution this does need that the metaclass needs
to execute code on the first class it is used for, in a PEP 487
solution this is not the case. A PEP 487 class HasTraits (no Meta
here) would not have Traits-descriptors itself, the classes inheriting
from it would have traits to be initialized. The PEP 487 HasTraits
takes the role of the metaclass.

A completely different problem shows up here. In your example,
HasTraits needs to initialize things on the class before the
Descriptors are run. This is not possible with PEP 487, where the
descriptors are initialized before __init_subclass__ is even called.

There are two ways to mitigate that problem:

- the first initialized descriptor could do the necessary initialization, or
- the descriptors are initialized from within __init_subclass__

At first sight, the first option seems hackish and the second option
looks much saner. Nonetheless PEP 487 proposes the second solution.
The rationale behind that is that people tend to forget to call
super(), and suddenly descriptors don't work anymore.

I realized later there is another benefit to this: if the first
initialized descriptor is doing the class initialization, often
__init_subclass__ isn't needed at all anymore, which means that those
kind of descriptors can be used on any class, without the need to tell
users that they have to inherit from a certain base class for the
descriptors to work. Only if some finalizing code needs to run after
the last descriptor is initialized one needs to write an
__init_subclass__. This is unavoidable as the last descriptor doesn't
know that it is the last.

Greetings

Martin
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Method signatures in the datetime module documentation

2016-07-29 Thread Alexander Belopolsky
I have started [1] writing documentation for the new PEP 495 (Local
Time Disambiguation) features and ran into the following problem.  The
current documentation is rather inconsistent in presenting the method
signatures.  For example:

date.replace(year, month, day) [2], but
datetime.replace([year[, month[, day[, hour[, minute[, second[,
microsecond[, tzinfo) [3].


The new signature for datetime.replace in the Python implementation is

def replace(self, hour=None, minute=None, second=None, microsecond=None,
tzinfo=True, *, fold=None):


but the C implementation does not accept True for tzinfo or None for
the other arguments.  The defaults in the Python implementation are
really just sentinels to detect which arguments are not provided.

How should I present the signature of the new replace method in the
documentation?


[1]: http://bugs.python.org/issue27595
[2]: https://docs.python.org/3/library/datetime.html#datetime.date.replace
[3]: https://docs.python.org/3/library/datetime.html#datetime.datetime.replace
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP487: Simpler customization of class creation

2016-07-29 Thread Ethan Furman

On 07/29/2016 08:01 AM, Martin Teichmann wrote:


... Also, while researching other
people's code when I wrote PEP 487, I couldn't find any such code
elsewhere, yet I found a lot of code where people took the wildest
measure to prevent a metaclass in doing its job on the first class it
is used for. One example is enum.EnumMeta, which contains code not to
make enum.Enum an enum ...


Actually, enum.Enum is an enum.  The guards are there because part of creating 
a new
Enum class is searching for the previous Enum classes, and of course the very 
first
time through there is no previous Enum class.

My apologies if I have misunderstood what you were trying to say.

--
~Ethan~
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com