[Python-Dev] Re: Last call for comments on PEP 573 (Module State Access from C Extension Methods)

2019-12-30 Thread Nick Coghlan
On Wed, 4 Dec 2019 at 09:44, Nick Coghlan  wrote:
>
> I have a few minor copy-editing comments, but I'll submit those as a PR to 
> the PEPs repo (it's nothing substantial, just a few wording clarifications, 
> and making sure the list of added methods is complete).

Belatedly working on those copy-editing updates, I noticed one
semantic change I'd like to make to the PEP.

At the moment PyType_GetModule() and PyType_GetModuleState() are
specified as raising SystemError if they are passed:

* a non-type object
* a non-heap type
* a heap type without ht_module set

Raising TypeError would be more appropriate than raising SystemError,
since this is really a standard case of "you passed in an object of a
type the API wasn't expecting".

A PR with this change (and the previously mentioned copy-editing
updates) is up at https://github.com/python/peps/pull/1264

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/HYUM3DZT6KM2O4SK2U2AY5AJAKABTEL5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Should set objects maintain insertion order too?

2019-12-30 Thread pylang
A set was requested with preserved insertion order.  Mathematically, such a
structure relates more to an Oset (having order) than a Set.  See
relationships in the image below:

[image: libo.png]

Each of the mentioned structure types has a dedicated role.  Python's sets
work well and correlate with existing math principles.  I would be more
convinced to introduce a new collection to Python rather than alter
existing sets.

-1: preserving insertion-order in sets
 0: adding `OrderedSet` (where `dict.fromkeys()` does not suffice, i.e.
needing set operations)
+1: implementing an analogous abstract collection, e.g. "`HashList`" ->
Oset, just as `Counter` -> Mset

On Sun, Dec 29, 2019 at 9:00 PM Wes Turner  wrote:

> Due to version and platform constraints, a SAT solver is necessary for
> conda and (now) pip. Libsolv is one of the fastest around.
>
>  https://github.com/QuantStack/mamba is conda implemented with libsolv
> (and parallel downloading of *declarative* dependency metadata).
>
> For general purpose graphs with implicit node instantation from edge
> declaration, NetworkX has implementations of many graph algorithms.
>
> https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.dag.topological_sort.html
>
>
> CuGraph (a product of the RAPIDS.ai project) does graphs with CUDA (from
> Python) with a "NetworkX-like API" but doesn't yet have a topological sort
> (though it does have BFS)
> https://github.com/rapidsai/cugraph
>
> "pip needs a dependency resolver" + End (Fn+Right) links to the latest
> work on the new pip code (that must require declarative dependency metadata)
> https://github.com/pypa/pip/issues/988
>
> That said, this implementation of topo sort could have a deterministic
> output given an OrderedSet:
> https://rosettacode.org/wiki/Topological_sort#Python
>
> A table including Big-O and memory usage for the necessary data structure
> and methods would be useful.
>
> On Sun, Dec 29, 2019, 5:12 PM Tim Peters  wrote:
>
>> [Larry]
>> > It's a lightweight abstract dependency graph.  Its nodes are opaque,
>> > only required to be hashable.  And it doesn't require that you give it
>> > all the nodes in strict dependency order.
>> >
>> > When you add a node, you can also optionally specify
>> > dependencies, and those dependencies aren't required
>> > to be nodes that the graph has previously seen.  So you can add
>> > a node A that depends on B and C, without showing it B or C
>> > first.  When that happens it creates placeholder nodes for B
>> > and C, and naturally these nodes have no dependencies.  You
>> > can then later inform the graph that node B has dependencies
>> > on X Y and Z.
>> >
>> > (My specific use case is a package manager.  Packages are identified
>> > with unique strings.  So the nodes I give the give the graph are simply
>> > those package names.  It's pretty common for me to get a package
>> > with dependencies on packages I haven't seen yet.  Designing the
>> > graph to create placeholders let me skip making two passes over
>> > the package list, pre-creating the package objects, etc etc.  This
>> > made the code simpler and presumably faster.)
>> >
>> > The graph API maintains an externally-visible "ready" iterable of
>> > nodes.  And since B can go from ready to not-ready, it can get added
>> > to "ready" and subsequently removed.
>> >
>> > Also, when a node is satisfied, you simply remove it from the graph.
>> >  If A depends on B and C, and they all represent jobs, and B and C
>> > have no dependencies, they'll be in the "ready" iterable.  You iterate
>> > over "ready", and execute those jobs, and assuming they are
>> > successful you then remove them from the graph.  When A's
>> > dependencies are all satisfied, it'll get added to the "ready" iterable.
>> >  And naturally when B and C were removed from the graph, they were
>> > removed from the "ready" iterable too.
>>
>> OK!  You're doing a topological sort.  There are natural & simple ways
>> to do that right now that scale efficiently to very large graphs (time
>> & space linear in the sum of the number of nodes and the number of
>> dependencies).  Curiously, the difficulties are mostly driven by the
>> quality of _error_ messages you want (in case of, e.g., cycles in the
>> dependency graph).
>>
>> Lots of those implementations became deterministic "by magic" when
>> ordered dicts were introduced.  This is why:  a bare bones
>> implementation needs to associate two pieces of info with each node:
>> a list of its immediate successors, and an integer count of the number
>> of its immediate predecessors.  A dict is the natural way to implement
>> that association.
>>
>> When all the dependency info has been entered, then:
>>
>> - First all nodes are emitted whose predecessor count is 0.  Iterating
>> over the association dict once is the natural way to find them, and
>> that order is defined now.
>>
>> - Then, as each emitted node N is marked done:
>>   for child in N.succe

[Python-Dev] PEP 558: Defined semantics for locals() (December 2019 edition)

2019-12-30 Thread Nick Coghlan
Hi folks,

I've finally updated PEP 558 and it's reference implementation based
on Nathaniel's feedback back in May.

The latest version of the PEP can now be found at
https://www.python.org/dev/peps/pep-0558/, and I've created a
discussion thread on Discourse:
https://discuss.python.org/t/pep-558-defined-semantics-for-locals/2936

The latest version implements Nathaniel's "independent snapshot"
proposal, and I like how that has turned out. The one thing that
changed from the May discussion thread is that the refcount semantics
of PyEval_GetLocals() (it returns a borrowed reference) meant that it
had to keep the old behaviour of returning a reference to the internal
dynamically updated shared "snapshot" at function scope, with a new
API, PyEval_GetPyLocals(), providing the C equivalent of the locals()
builtin.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/GHN2GYJQRU77EZBXX4SQUZ5XEMEONSFL/
Code of Conduct: http://python.org/psf/codeofconduct/