profile
viewpoint

bbcmicrobit/micropython 439

Port of MicroPython for the BBC micro:bit

gvanrossum/500lines 203

500 Lines or Less

gvanrossum/pegen 141

PEG parser generator for Python

gvanrossum/pyxl3 106

A Python 3 extension for writing structured and reusable inline HTML.

gvanrossum/cpython 58

The Python programming language

gvanrossum/ctok 51

Expose CPython's tokenizer as a Python class

ilevkivskyi/com2ann 49

Tool for translation type comments to type annotations in Python

edreamleo/make-stub-files 20

Script and config file that creates python stub (.pyi) files

gvanrossum/pythonlabs 16

Reconstructed source code for pythonlabs.com

issue commentgvanrossum/pegen

Integration into CPython

I like having a branch we can all push to. That's (nearly) what I've been using for the PEP 585 work (the branch is owned by my own cpython fork and I just accept PRs against the branch in my fork).

The speed is now much closer to that of the old parser (within 20% probably). Did this come from profiling or from intuition alone?

The next challenge is memory usage. (If you want to discuss specific ideas about that, one of you should open a new issue for that topic.)

gvanrossum

comment created time in an hour

pull request commentpython/cpython

bpo-39481: WIP: Implementation for PEP 585

Per https://mail.python.org/archives/list/python-dev@python.org/message/EYU3VDK7T4OVT7MXM5OWOPFA4YKWXVDE/, let's add a standard __class_getitem__ to the mappingproxy type (descrobject.c, line 1717; a.k.a. types.MappingProxyType). This is the type used for the __dict__ attribute of class objects (it's a read-only proxy) and it is generic in typeshed.

gvanrossum

comment created time in 15 hours

issue commentgvanrossum/pegen

Integration into CPython

I think that what you're missing is that if it is met with approval (or at worst "meh") at the summit, it will be a big project to do the integration. If we started a "WIP" PR with the integration work now we would be able to do things quicker once we have the green light.

I don't know if it was written up already, but I think we decided that there should be a command-line flag to Python to enable this. In the last alpha and in the first beta the default should be the old parser. Then in later betas the default should be the new parser. This way we may be able to keep the old 'parser' module around in 3.9 (since a little birdie told me that PEP 594, which proposes to kill 'parser' in 3.9, may be deferred to 3.10).

I'd also like to have an explicit way to invoke the new parser even when the command-line flag specifies the old parser (e.g. for unit-testing the new parser). This should just be importing something (or perhaps an alternative API in the ast module).

Also, hat happened to performance?!! It's almost twice as fast now. If that's true, that's fantastic!

gvanrossum

comment created time in 16 hours

pull request commentpython/peps

PEP 615: Add PEP proposing zoneinfo module

It's not great to have the discussion happening in the PR proposing to add the PEP. Where do you propose to have the discussion? python-ideas, python-dev, discuss.python.org, or somewhere else? (Is there a datetime-sig? I've forgotten.)

pganssle

comment created time in 16 hours

pull request commentpython/cpython

bpo-39649: Remove obsolete check for `__args__` in bdb.Bdb.format_stack_entry

Should this be backported, or does the change reflect a 3.9-only change in f_locals?

It can be backported -- after all the commit the OP mentioned that makes this check obsolete happened in 1998.

PS, still waiting for the OP (@blueyed) to add a news entry.

blueyed

comment created time in 16 hours

issue commentpython/typed_ast

Fails to cross compile

I have zero experience with cross compiling. But if you can come up with a fix, please submit a PR.

CameronNemo

comment created time in 2 days

push eventpython/cpython

ananthan-123

commit sha fbe2e0bb8a7ee75d0f9d57682436dac7d69e202e

bpo-17422: Language reference should specify restrictions on class namespace (#18559) The language reference now specifies restrictions on class namespaces. Adapted from a patch by Ethan Furman.

view details

push time in 2 days

PR merged python/cpython

Reviewers
bpo-17422:language reference should specify restrictions on class namespace CLA signed awaiting merge type-documentation

<!-- Thanks for your contribution! Please read this comment in its entirety. It's quite important.

Pull Request title

It should be in the following format:

bpo-NNNN: Summary of the changes made

Where: bpo-NNNN refers to the issue number in the https://bugs.python.org.

Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.

Backport Pull Request title

If this is a backport PR (PR made against branches other than master), please ensure that the PR title is in the following format:

[X.Y] <title from the original PR> (GH-NNNN)

Where: [X.Y] is the branch name, e.g. [3.6].

GH-NNNN refers to the PR number from master.

-->

<!-- issue-number: bpo-17422 --> https://bugs.python.org/issue17422 <!-- /issue-number -->

+5 -2

0 comment

2 changed files

ananthan-123

pr closed time in 2 days

Pull request review commentpython/cpython

bpo-17422:language reference should specify restrictions on class namespace

+Language reference should specify restrictions on class namespace.

Please attribute the patch to its author here.

ananthan-123

comment created time in 5 days

Pull request review commentgvanrossum/pegen

Only store lineno/col_offset if EXTRA is used in the action

 def _handle_default_rule_body(self, node: Rule, rhs: Rhs, result_type: str) -> N                 with self.indent():                     self.print("return res;")             self.print("int mark = p->mark;")-            self._set_up_token_start_metadata_extraction()+            for alt in rhs.alts:

Please code this using ‘any()’ instead of loop and break.

lysnikolaou

comment created time in 3 days

pull request commentgvanrossum/pegen

Measure true parsing speed, in case the produced AST tree is not needed

Hm, this still measures butecode compilation time IIUC

lysnikolaou

comment created time in 3 days

pull request commentgvanrossum/pegen

Reject invalid expressions in the for-if clauses of a comprehension

Indeed, but presumably that to match the old parser.

I was hypothesizing that using pegen will allow us to see some restrictions in the grammar and let us relax them. Though on second thought probably not this case.

lysnikolaou

comment created time in 4 days

pull request commentgvanrossum/pegen

Set simple=0 on attribute and subscript assignments

Huh, looks like several other PRs ended up in this?

isidentical

comment created time in 4 days

pull request commentgvanrossum/pegen

Reject invalid expressions in the for-if clauses of a comprehension

Relaxation: turn e.g. disjunction into expression. But in this case probably there’s a reason.

lysnikolaou

comment created time in 4 days

pull request commentgvanrossum/pegen

Reject invalid expressions in the for-if clauses of a comprehension

+1 on the test fix too.

lysnikolaou

comment created time in 4 days

pull request commentpython/cpython

bpo-39684: Combine two if/thens

Then can you ask for git help somewhere? The PR definitely doesn’t look right (click on Changes to see for yourself — it should only show your changes, but it shows other things) and all I have here is a phone.

--Guido (mobile)

petdance

comment created time in 5 days

pull request commentpython/cpython

bpo-39684: Combine two if/thens

Something went wrong with git. You should probably fetch from upstream and rebase.

petdance

comment created time in 5 days

push eventpython/cpython

ananthan-123

commit sha ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0

bpo-39572: Document ’total’ flag of TypedDict (GH-18554)

view details

push time in 6 days

PR merged python/cpython

Reviewers
bpo-39572:documented _total_ attribute of TypedDict CLA signed awaiting merge

<!-- Thanks for your contribution! Please read this comment in its entirety. It's quite important.

Pull Request title

It should be in the following format:

bpo-NNNN: Summary of the changes made

Where: bpo-NNNN refers to the issue number in the https://bugs.python.org.

Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.

Backport Pull Request title

If this is a backport PR (PR made against branches other than master), please ensure that the PR title is in the following format:

[X.Y] <title from the original PR> (GH-NNNN)

Where: [X.Y] is the branch name, e.g. [3.6].

GH-NNNN refers to the PR number from master.

-->

<!-- issue-number: bpo-39572 --> https://bugs.python.org/issue39572 <!-- /issue-number -->

+29 -3

3 comments

3 changed files

ananthan-123

pr closed time in 6 days

push eventananthan-123/cpython

Guido van Rossum

commit sha cd1ddb8fefd0e8fc1fcc729f751a1025cea07be8

Fixed markup.

view details

push time in 6 days

pull request commentpython/peps

PEP 581: Fix switched reference links

Thanks!

chrahunt

comment created time in 6 days

push eventpython/peps

Christopher Hunt

commit sha 229df87c1fe696863b0a5818c963d773861b9bd6

PEP 581: Fix switched reference links (#1312)

view details

push time in 6 days

PR merged python/peps

PEP 581: Fix switched reference links CLA signed

In the "Downsides of GitHub" section, the references for "backing up GitHub" and "increasing triage effort" were switched. Now they are correct.

On the PEPs website here these are 15 and 16.

+3 -3

2 comments

1 changed file

chrahunt

pr closed time in 6 days

pull request commentpython/peps

PEP 581: Fix switched reference links

Oh wait. You marked it as draft. Remove the draft flag when you are ready for it to be merged.

chrahunt

comment created time in 6 days

pull request commentpython/cpython

bpo-39481: WIP: Implementation for PEP 585

I honestly don’t think it’s important.

On Tue, Feb 18, 2020 at 18:42 Ethan Smith notifications@github.com wrote:

@ethanhs commented on this pull request.

In Objects/descrobject.c https://github.com/python/cpython/pull/18239#discussion_r381049447:

  • Py_DECREF(eq);
  • return PyObject_RichCompare(aa->args, bb->args, Py_EQ); +}

+static PyObject * +ga_mro_entries(PyObject *self, PyObject *args) +{

  • gaobject *alias = (gaobject *)self;
  • return PyTuple_Pack(1, alias->origin); +}

+static PyObject * +ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored)) +{

  • return PyErr_Format(PyExc_TypeError,
  •                    "TypeError: Subscripted generics cannot be used with class and instance checks",
    

Okay hm, for the case of:

issubclass(list[str], list)

I'm stumped. Perhaps this needs to be implemented in the builtin isinstance/issubclass? Otherwise I don't see how to prevent that pattern.

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/python/cpython/pull/18239?email_source=notifications&email_token=AAWCWMSKV7COWPFQ7T5IAA3RDSMC3A5CNFSM4KMUS5T2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCWAYKYA#discussion_r381049447, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWCWMUIVCEOKVWICPWQTYTRDSMC3ANCNFSM4KMUS5TQ .

-- --Guido (mobile)

gvanrossum

comment created time in 6 days

Pull request review commentpython/cpython

bpo-39572:documented _total_ attribute of TypedDict

+Updated _total_ attribute of TypeDict.

There's an attribute __total__, which your docs do not mention (nor does the PEP, so it needn't be mentioned), and a class "flag" (not "attribute") named total. We don't use the convention _word_ much for emphasis, so I recommend using either single quotes ('total') or backticks (`total`) here.

ananthan-123

comment created time in 6 days

pull request commentpython/cpython

bpo-39572:documented _total_ attribute of TypedDict

Note that the importlib failure is pre-existing (and presumably being worked on). I'll try to review later, but I am going out of town for a ew days.

ananthan-123

comment created time in 6 days

Pull request review commentpython/cpython

bpo-39481: WIP: Implementation for PEP 585

 PyTypeObject PyProperty_Type = {     PyType_GenericNew,                          /* tp_new */     PyObject_GC_Del,                            /* tp_free */ };+++// Experimental code to implement PEP 585 (list[int] etc.)+// TODO: Does this belong in this file?++typedef struct {+    PyObject_HEAD+    PyObject *origin;+    PyObject *args;+    PyObject *parameters;+} gaobject;++static void+ga_dealloc(PyObject *self)+{+    gaobject *alias = (gaobject *)self;++    _PyObject_GC_UNTRACK(self);+    Py_XDECREF(alias->origin);+    Py_XDECREF(alias->args);+    Py_XDECREF(alias->parameters);+    self->ob_type->tp_free(self);+}++static int+ga_traverse(PyObject *self, visitproc visit, void *arg)+{+    gaobject *alias = (gaobject *)self;+    Py_VISIT(alias->origin);+    Py_VISIT(alias->args);+    Py_VISIT(alias->parameters);+    return 0;+}++static int+ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)+{+    PyObject *qualname = PyObject_GetAttrString(p, "__qualname__");+    PyErr_Clear();+    PyObject *module = PyObject_GetAttrString(p, "__module__");+    PyErr_Clear();+    PyObject *r = NULL;+    int err;+    if (PyObject_HasAttrString(p, "__origin__") &&+        PyObject_HasAttrString(p, "__args__"))+    {+        // It looks like a GenericAlias+        r = PyObject_Repr(p);+    }+    else if (p == Py_Ellipsis) {+        // The Ellipsis object+        r = PyUnicode_FromString("...");+    }+    else if (qualname != NULL && module != NULL) {+        // Looks like a class+        if (PyUnicode_CompareWithASCIIString(module, "builtins") == 0) {+            // builtins don't need a module name+            Py_INCREF(qualname);+            r = qualname;+        }+        else {+            r = PyUnicode_FromFormat("%U.%U", module, qualname);+        }+    }+    else {+        // fallback+        r = PyObject_Repr(p);+    }+    if (r == NULL) {+        // error if any of the above PyObject_Repr/PyUnicode_From* fail+        err = -1;+    } else {+        err = _PyUnicodeWriter_WriteStr(writer, r);+    }+    Py_XDECREF(qualname);+    Py_XDECREF(module);+    Py_XDECREF(r);+    return err;+}++static PyObject *+ga_repr(PyObject *self)+{+    gaobject *alias = (gaobject *)self;+    Py_ssize_t len = PyTuple_Size(alias->args);++    _PyUnicodeWriter writer;+    _PyUnicodeWriter_Init(&writer);+    +    if (ga_repr_item(&writer, alias->origin) < 0) {+        goto error;+    }+    if (_PyUnicodeWriter_WriteASCIIString(&writer, "[", 1) < 0) {+        goto error;+    }+    for (Py_ssize_t i = 0; i < len; i++) {+        if (i > 0) {+            if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) {+                goto error;+            }+        }+        PyObject *p = PyTuple_GET_ITEM(alias->args, i);+        if (ga_repr_item(&writer, p) < 0) {+            goto error;+        }+    }+    if (len == 0) {+        // for something like tuple[()] we should print a "()"+        if (_PyUnicodeWriter_WriteASCIIString(&writer, "()", 2) < 0) {+            goto error;+        }+    }+    if (_PyUnicodeWriter_WriteASCIIString(&writer, "]", 1) < 0) {+        goto error;+    }+    return _PyUnicodeWriter_Finish(&writer);+error:+    _PyUnicodeWriter_Dealloc(&writer);+    return NULL;+}++// isinstance(obj, TypeVar) without importing typing.py.  If someone+// names some other class TypeVar, it will be mistaken for a TypeVar.+// Maybe that's a feature; or maybe we'll have to see if+// sys.modules['typing'] exists and look for its 'TypeVar' attribute+// (which is roughly what dataclasses.py uses to recognize ClassVar).+static int+is_typevar(PyObject *obj)+{+    PyTypeObject *type = Py_TYPE(obj);+    return strcmp(type->tp_name, "TypeVar") == 0;+}++// Index of item in self[:len], or -1 if not found (self is a tuple)+static Py_ssize_t+tuple_index(PyObject *self, Py_ssize_t len, PyObject *item)+{+    for (Py_ssize_t i = 0; i < len; i++) {+        if (PyTuple_GET_ITEM(self, i) == item) {+            return i;+        }+    }+    return -1;+}++// tuple(t for t in args if isinstance(t, TypeVar))+static PyObject *+make_parameters(PyObject *args)+{+    Py_ssize_t len = PyTuple_GET_SIZE(args);+    PyObject *parameters = PyTuple_New(len);+    if (parameters == NULL)+        return NULL;+    Py_ssize_t iparam = 0;+    for (Py_ssize_t iarg = 0; iarg < len; iarg++) {+        PyObject *t = PyTuple_GET_ITEM(args, iarg);+        if (is_typevar(t)) {+            if (tuple_index(parameters, iparam, t) < 0) {+                Py_INCREF(t);+                PyTuple_SET_ITEM(parameters, iparam, t);+                iparam++;+            }+        }+    }+    if (iparam < len) {+        if (_PyTuple_Resize(&parameters, iparam) < 0) {+            Py_XDECREF(parameters);+            return NULL;+        }+    }+    return parameters;+}++static PyObject *+ga_getitem(PyObject *self, PyObject *item)+{+    gaobject *alias = (gaobject *)self;+    Py_ssize_t nparams = PyTuple_GET_SIZE(alias->parameters);+    if (nparams == 0) {+        return PyErr_Format(PyExc_TypeError,+                            "There are no type variables left in %R",+                            self);+    }+    int is_tuple = PyTuple_Check(item);+    Py_ssize_t nitem = is_tuple ? PyTuple_GET_SIZE(item) : 1;+    if (nitem != nparams) {+        return PyErr_Format(PyExc_TypeError,+                            "Too %s arguments for %R",+                            nitem > nparams ? "many" : "few",+                            self);+    }+    Py_ssize_t nargs = PyTuple_GET_SIZE(alias->args);+    PyObject *newargs = PyTuple_New(nargs);+    if (newargs == NULL)+        return NULL;+    for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {+        PyObject *arg = PyTuple_GET_ITEM(alias->args, iarg);+        if (is_typevar(arg)) {+            Py_ssize_t iparam = tuple_index(alias->parameters, nparams, arg);+            assert(iparam >= 0);+            if (is_tuple) {+                arg = PyTuple_GET_ITEM(item, iparam);+            }+            else {+                assert(iparam == 0);+                arg = item;+            }+        }+        Py_INCREF(arg);+        PyTuple_SET_ITEM(newargs, iarg, arg);+    }+    PyObject *res = Py_GenericAlias(alias->origin, newargs);+    Py_DECREF(newargs);+    return res;+}++static PyMappingMethods ga_as_mapping = {+    .mp_subscript = ga_getitem,+};++static PyObject *+ga_call(PyObject *self, PyObject *args, PyObject *kwds)+{+    gaobject *alias = (gaobject *)self;+    PyObject *obj = PyObject_Call(alias->origin, args, kwds);+    if (obj != NULL) {+        PyObject_SetAttrString(obj, "__orig_class__", self);+        PyErr_Clear();+    }+    return obj;+}++static const char* const attr_exceptions[] = {+    "__origin__",+    "__args__",+    "__parameters__",+    "__mro_entries__",+    "__reduce_ex__",  // needed so we don't look up object.__reduce_ex__+    "__reduce__",+    "__setstate__",+    NULL,+};++static PyObject *+ga_getattro(PyObject *self, PyObject *name)+{+    gaobject *alias = (gaobject *)self;+    if (PyUnicode_Check(name)) {+        for (const char * const *p = attr_exceptions; ; p++) {+            if (*p == NULL) {+                return PyObject_GetAttr(alias->origin, name);+            }+            if (PyUnicode_CompareWithASCIIString(name, *p) == 0) {+                break;+            }+        }+    }+    return PyObject_GenericGetAttr(self, name);+}++static PyObject *+ga_richcompare(PyObject *a, PyObject *b, int op)+{+    if (Py_TYPE(a) != &Py_GenericAliasType ||+        Py_TYPE(b) != &Py_GenericAliasType ||+        (op != Py_EQ && op != Py_NE))+    {+        Py_RETURN_NOTIMPLEMENTED;+    }++    if (op == Py_NE) {+        PyObject *eq = ga_richcompare(a, b, Py_EQ);+        if (eq == NULL)+            return NULL;+        Py_DECREF(eq);+        if (eq == Py_True) {+            Py_RETURN_FALSE;+        }+        else {+            Py_RETURN_TRUE;+        }+    }++    gaobject *aa = (gaobject *)a;+    gaobject *bb = (gaobject *)b;+    PyObject *eq = PyObject_RichCompare(aa->origin, bb->origin, Py_EQ);+    if (eq == NULL)+        return NULL;+    if (eq == Py_False) {+        return eq;+    }+    Py_DECREF(eq);+    return PyObject_RichCompare(aa->args, bb->args, Py_EQ);+}++static PyObject *+ga_mro_entries(PyObject *self, PyObject *args)+{+    gaobject *alias = (gaobject *)self;+    return PyTuple_Pack(1, alias->origin);+}++static PyObject *+ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored))+{+    return PyErr_Format(PyExc_TypeError,+                        "TypeError: Subscripted generics cannot be used with class and instance checks",+                        self);+}++static PyObject *+ga_subclasscheck(PyObject *self, PyObject *Py_UNUSED(ignored))+{+    return PyErr_Format(PyExc_TypeError,+                        "TypeError: Subscripted generics cannot be used with class and instance checks",+                        self);+}++static PyObject *+ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))+{+    gaobject *alias = (gaobject *)self;+    return Py_BuildValue("O(OO)", Py_TYPE(alias),+                         alias->origin, alias->args);+}++static PyObject *+ga_setstate(PyObject *self, PyObject *state)+{+    gaobject *alias = (gaobject *)self;+    PyObject *parameters = make_parameters(alias->args);+    Py_INCREF(parameters);+    alias->parameters = parameters;+    Py_RETURN_NONE;+}++static PyMethodDef ga_methods[] = {+    {"__mro_entries__", ga_mro_entries, METH_O},+    {"__instancecheck__", ga_instancecheck, METH_O},+    {"__subclasscheck__", ga_subclasscheck, METH_O},+    {"__reduce__", ga_reduce, METH_NOARGS},+    {"__setstate__", ga_setstate, METH_O},+    {0}+};++static PyMemberDef ga_members[] = {+    {"__origin__", T_OBJECT, offsetof(gaobject, origin), READONLY},+    {"__args__", T_OBJECT, offsetof(gaobject, args), READONLY},+    {"__parameters__", T_OBJECT, offsetof(gaobject, parameters), READONLY},+    {0}+};++static PyObject *+ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)+{+    if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) {+        return PyErr_Format(PyExc_TypeError, "GenericAlias does not support keyword arguments");+    }+    if (PyTuple_Size(args) != 2) {+        return PyErr_Format(PyExc_TypeError, "GenericAlias expects 2 positional arguments");+    }+    PyObject *origin = PyTuple_GET_ITEM(args, 0);+    PyObject *arguments = PyTuple_GET_ITEM(args, 1);+    return Py_GenericAlias(origin, arguments);+}++// TODO:+// - argument clinic?+// - __doc__?+// - cache?+PyTypeObject Py_GenericAliasType = {+    PyVarObject_HEAD_INIT(&PyType_Type, 0)+    .tp_name = "types.GenericAlias",

Agreed that GenericAlias is a lame name for the concept. It's easy to change now, but will be impossible to change once the PEP's been accepted, so it's appropriate to bikeshed about it (here, and maybe in the list). At first blush I do like GenericType.

gvanrossum

comment created time in 6 days

pull request commentpython/cpython

bpo-39481: WIP: Implementation for PEP 585

FWIW I think I've convinced Łukasz that we should reject isinstance(x, list[str]) and issubclass(C, list[str]). Are there other things where this PR deviates from PEP 585?

gvanrossum

comment created time in 6 days

issue closedpython/mypy

ReadTheDocs build failures

Somehow the readthedocs build failure emails go to me, and I've seen two failures lately. The latest is: https://readthedocs.org/projects/mypy/builds/10315378/

closed time in 7 days

gvanrossum

issue commentpython/mypy

ReadTheDocs build failures

Indeed. Thanks!

gvanrossum

comment created time in 7 days

pull request commentgvanrossum/pegen

WIP: Correctly shift node position in multi-line fstrings

I think we should strive for parity with CPython first.

I agree that in the long run we may have to rewrite f-string parsing from scratch -- and Eric V Smith seems to agree (see https://bugs.python.org/issue39564), but that's going to require changes to the tokenizer. If this gets done in 3.9 we'll have to track that, but my money is on 3.10 or later, given the complexity of the edge cases (things like ...{x:4d}... and ...{x = :.5g}... -- and note that currently the walrus doesn't work, e.g. ...{x := 1}...).

lysnikolaou

comment created time in 7 days

pull request commentpython/peps

PEP 584: Apply feedback from the Python-Dev discussion.

Your next step would be to email steering-council@python.org with a request to review and hopefully approve this PEP.

Whoops, I forgot I am already BDFL-Delegate myself. So I'll just announce that I'm accepting it.

brandtbucher

comment created time in 7 days

pull request commentgvanrossum/pegen

WIP: Correctly shift node position in multi-line fstrings

I hope Pablo can review this... I'm not at all confident I understand the f-string code.

There's one thing that concerns me though -- why focus all attention on the column offset? Isn't the line number also subject to movement? E.g. in

f"""blah
{
expr)
}
"""

Don't we want the error to point to the ) rather than to the start of the f-string?

lysnikolaou

comment created time in 7 days

pull request commentpython/peps

PEP 584: Apply feedback from the Python-Dev discussion.

Brandt,

Your next step would be to email steering-council@python.org with a request to review and hopefully approve this PEP.

--Guido

brandtbucher

comment created time in 7 days

push eventpython/peps

Brandt Bucher

commit sha 718b39388739eb3774dea2bd6276acf6a47d8c75

PEP 584: Apply feedback from the Python-Dev discussion. (#1309)

view details

push time in 7 days

PR merged python/peps

PEP 584: Apply feedback from the Python-Dev discussion. CLA signed

These are just a collection of clarifications that were requested on- and off-list.

+28 -11

1 comment

1 changed file

brandtbucher

pr closed time in 7 days

pull request commentgvanrossum/pegen

Set simple=0 on attribute and subscript assignments

I've nothing to add, somebody please do the perf research and propose a final patch (maybe as a separate PR).

isidentical

comment created time in 7 days

Pull request review commentpython/peps

PEP 584: Apply feedback from the Python-Dev discussion.

 An *approximate* pure-Python implementation is::     def __or__(self, other):         if not isinstance(other, dict):             return NotImplemented-        new = self.copy()+        new = dict.copy(self)

I typically spell this dict(self).

brandtbucher

comment created time in 7 days

Pull request review commentpython/peps

PEP 584: Apply feedback from the Python-Dev discussion.

 ChainMap will modify the original dict::       {'eggs': 999}  +------------------+``dict(d1, **d2)``+------------------++This "neat trick" is not well-known, and only works when ``d2`` is+entirely string-keyed::++    >>> d1 = {"spam": 1}+    >>> d2 = {3665: 2}+    >>> dict(d1, **d2)+    Traceback (most recent call last):+      ...+    TypeError: keywords must be strings++Even then, it should not be promoted as the "one obvious way".  Guido+`said it best+<https://mail.python.org/archives/list/python-dev@python.org/message/FM66WWN5YFCMRGMRWGHACOXLQYTWNXE2/>`_:++    Apparently dict(x, \*\*y) is going around as "cool hack" for "call+    x.update(y) and return x". Personally I find it more despicable+    than cool.

I don't think my emotional response adds much insight to the PEP (I also misstated the trick). I think the fact that it only works for string keys is enough to sink it.

brandtbucher

comment created time in 7 days

pull request commentpython/cpython

bpo-39649: Remove obsolete check for `__args__` in bdb.Bdb.format_stack_entry

Shall we add some unittest? in case this logic will be break in future.

I don't see why -- we're removing logic that was never functional in the first place. There's no need to test for that.

blueyed

comment created time in 8 days

pull request commentpython/cpython

bpo-39649: Remove obsolete check for `__args__` in bdb.Bdb.format_stack_entry

Could you add a news entry? You can probably ignore the Codecov "failure".

blueyed

comment created time in 8 days

Pull request review commentgvanrossum/pegen

Fix segfault in debug mode when raising syntax errors

 def f(*a, b):     ("f-string_lambda", "f'{lambda x: 42}'"),     ("f-string_singe_brace", "f'{'"),     ("f-string_single_closing_brace", "f'}'"),+    ("invalid indentation",+     """+     def f():+         a+             a+     """),

Ah, makes sense, and I trust you -- setting up a debug build takes too long. :-)

Note that I fixed emited -> emitted.

pablogsal

comment created time in 8 days

push eventpablogsal/pegen

Guido van Rossum

commit sha 7f8c8d52efa242a870e434806082056cda9ed0aa

emitted

view details

push time in 8 days

Pull request review commentgvanrossum/pegen

Fix segfault in debug mode when raising syntax errors

 def f(*a, b):     ("f-string_lambda", "f'{lambda x: 42}'"),     ("f-string_singe_brace", "f'{'"),     ("f-string_single_closing_brace", "f'}'"),+    ("invalid indentation",

(Maybe add a comment that this test is really testing the uninitialized col_offset issue this bug is fixing?)

pablogsal

comment created time in 8 days

Pull request review commentgvanrossum/pegen

Fix segfault in debug mode when raising syntax errors

 def f(*a, b):     ("f-string_lambda", "f'{lambda x: 42}'"),     ("f-string_singe_brace", "f'{'"),     ("f-string_single_closing_brace", "f'}'"),+    ("invalid indentation",+     """+     def f():+         a+             a+     """),

Hm... I added this without the fix, and I the tests passed -- no segfault. This was on macOS though.

pablogsal

comment created time in 8 days

Pull request review commentgvanrossum/pegen

Fix segfault in debug mode when raising syntax errors

 raise_syntax_error(Parser *p, const char *errmsg, ...)             goto error;         }     }-    Py_ssize_t col_number = byte_offset_to_character_offset(loc, t->col_offset) + 1;+    // We may receive tokens with the col_offset not initialized (-1) since+    // emmited by fill_token(). For instance, this can happen in some error

emitted

pablogsal

comment created time in 8 days

push eventpython/peps

Brandt Bucher

commit sha b34adc092eb4e577b4ff406df7a46920a84d5761

PEP 614: Remove matmul section and clarify the current restrictions (#1305)

view details

push time in 11 days

PR merged python/peps

PEP 614: Remove matmul section and clarify the current restrictions. CLA signed

Also fix the post history.

+4 -26

0 comment

1 changed file

brandtbucher

pr closed time in 11 days

PR merged python/cpython

Reviewers
bpo-39627: Fix TypedDict totality check for inherited keys CLA signed awaiting merge

I realized that the inheritance of TypedDict does not work as it should.

class BaseAnimal(TypedDict):
     name: str

class Animal(_Animal, total=False):
     voice: str

class Cat(Animal):
     fur_color: str

I would assume that Cat should have required keys name and fur_color and optional voice. But in reality, it will have required fur_color and optional name and voice, because Animal has total=False

Fixed

  • __required_keys__ and __optional_keys__ are copied from base classes
  • Own TypedDict annotations are added to __annotations__ after base annotations

<!-- issue-number: bpo-39627 --> https://bugs.python.org/issue39627 <!-- /issue-number -->

+53 -13

2 comments

3 changed files

vemel

pr closed time in 11 days

push eventpython/cpython

Vlad Emelianov

commit sha 10e87e5ef4c1b4fb8415d9ddc362e2591f2f0b6c

bpo-39627: Fix TypedDict totality check for inherited keys (#18503) (Adapted from https://github.com/python/typing/pull/700)

view details

push time in 11 days

issue commentpython/typed_ast

typed_ast.ast27 crashes on coding declarations

Confirmed, and also confirmed that the stdlib ast module doesn't have this problem (in Python 3.7, 3.8 and in Python 2.7). Ironically, passing it a Unicode string with an encoding declaration doesn't trigger this error.

(I wouldn't call it a crash though. It's reporting a SyntaxError.)

@r3m0t, do you feel up to trying to coming up with a fix?

r3m0t

comment created time in 11 days

pull request commentpython/cpython

bpo-39627: Fix TypedDict totality check for inherited keys

Can you fix the test? To run locally, build python.exe or python (by running ./configure; make -j) and then /.python[.exe] -m test test_typing -v

Also, please add a news item, and a reference to the fix in the python/typing repo.

vemel

comment created time in 11 days

pull request commentpython/cpython

bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b.

Honestly I take it back, you can land.

serhiy-storchaka

comment created time in 12 days

pull request commentpython/cpython

bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b.

I don't need complex example, but I'd like a single example showing ((a)).b, since IIRC there's some special code involved in removing redundant parentheses, and I feel that that special case was involved in the bug in the first place.

serhiy-storchaka

comment created time in 12 days

pull request commentgvanrossum/pegen

WIP: Add f-string support

Oh, given that we have that switch it makes sense to exercise every case!

pablogsal

comment created time in 13 days

push eventpython/typing

Vlad Emelianov

commit sha e796957d1b6a50633dff1eb50ffdc22f0f2e2c35

Fix required and optional keys inheritance for TypedDict (#700) (For a complete description of the issue see https://github.com/python/typing/pull/700.)

view details

push time in 13 days

PR merged python/typing

Reviewers
Fix required and optional keys inheritance for TypedDict CLA signed

I realized that the inheritance of TypedDict does not work as it should.

class _Animal(TypedDict):
     name: str

class Animal(_Animal, total=False):
     voice: str

class Cat(Animal):
     fur_color: str

I would assume that Cat should have required keys name and fur_color and optional voice. But in reality, it will have required fur_color and optional name and voice, because Animal has total=False

Fixed

  • __required_keys__ and __optional_keys__ are copied from base classes
  • Own TypedDict annotations are added to __annotations__ after base annotations
  • Conflicting required and optional keys from base classes are removed if TypedDict redefines them
+54 -13

2 comments

2 changed files

vemel

pr closed time in 13 days

issue commentgvanrossum/pegen

Column offset bug in parenthesised Attribute nodes

The example in the bpo issue makes it clear why this is a real problem.

lysnikolaou

comment created time in 13 days

pull request commentgvanrossum/pegen

WIP: Add f-string support

Ideally we would have a way to state that a test is considered passing despite a given end column mismatch. But that seems complex give the current approach (diff the ast.dump() output), so xfail seems fine, for a few tests that only verify column offsets for f-string concatenation.

Why do we need to test every representative case inside f-strings? If, say, f"{1 + 1}" works, I am confident that f"{a().b()}" also works. But we should test edge cases, e.g. {{ and }}, as well as things like !r, = and :12d, and some edge cases (e.g. spaces before/after =).

pablogsal

comment created time in 13 days

push eventpython/typing

Vlad Emelianov

commit sha fdc9359289dd0a30ca90ad9d476ecd69a93b1973

Replace asyncio.coroutine with async-await (#702)

view details

push time in 13 days

PR merged python/typing

Replace asyncio.coroutine with async-await CLA signed

asyncio.coroutine decorator is deprecated in Python 3.8. I replaced it with async-await syntax. This change only affects unit tests.

New syntax should work in Python 3.5+, but I checked only 3.8.1.

Fixed

  • DeprecationWarning in AsyncIteratorWrapper in unit tests
+2 -4

0 comment

1 changed file

vemel

pr closed time in 13 days

Pull request review commentpython/typing

Fix required and optional keys inheritance for TypedDict

 class LabelPoint2D(Point2D, Label): ... class Options(TypedDict, total=False):     log_level: int     log_path: str++class _Animal(TypedDict):+    name: str++class Animal(_Animal, total=False):+    voice: str+    tail: bool++class Cat(Animal):+    fur_color: str+    tail: int

This isn't allowed by mypy (you can't change the type of an attribute in a subclass) so I recommend deleting the tail attribute altogether.

vemel

comment created time in 13 days

Pull request review commentpython/typing

Fix required and optional keys inheritance for TypedDict

 class LabelPoint2D(Point2D, Label): ... class Options(TypedDict, total=False):     log_level: int     log_path: str++class _Animal(TypedDict):

I don't see a reason for this class name to start with _ -- maybe rename to BaseAnimal?

vemel

comment created time in 13 days

push eventpython/typing

Jakub Stasiak

commit sha f3e77b4656ae865456356fa8486ed6363312069a

Reuse stdlib PEP 593 implementation in typing_extensions if present (#699) Following [1] this prevents multiple runtime implementations of Annotated and get_type_hints from existing on Python 3.9 (which has recently merged PEP 593 changes[2]). Reexporting allows code targetting both Python pre-3.9 and 3.9+ to be able to import from typing_extensions and to keep working without changes. [1] https://github.com/python/cpython/pull/18260#issuecomment-582486917 [2] https://github.com/python/cpython/pull/18260

view details

push time in 13 days

PR merged python/typing

Reuse stdlib PEP 593 implementation in typing_extensions if present CLA signed

Following [1] this prevents multiple runtime implementations of Annotated and get_type_hints from existing on Python 3.9 (which has recently merged PEP 593 changes[2]). Reexporting allows code targetting both Python pre-3.9 and 3.9+ to be able to import from typing_extensions and to keep working without changes.

_AnnotatedAlias import is needed for https://github.com/python/typing/pull/698 to work.

[1] https://github.com/python/cpython/pull/18260#issuecomment-582486917 [2] https://github.com/python/cpython/pull/18260

+8 -1

0 comment

1 changed file

jstasiak

pr closed time in 13 days

pull request commentpython/typing

Fix required and optional keys inheritance for TypedDict

Should this also be updated upstream in CPython?

vemel

comment created time in 13 days

pull request commentpython/cpython

Correct the documented default encoding

Probably, but we don't need to update ancient docs (3.6 and earlier can only be updated by their release managers).

eric-wieser

comment created time in 13 days

push eventpython/peps

Brandt Bucher

commit sha 85c431c827eb81a0ca70076fe57c983c4daab99d

PEP 614: Relaxing Grammar Restrictions On Decorators (#1303)

view details

push time in 13 days

PR merged python/peps

PEP 614: Relaxing Grammar Restrictions On Decorators CLA signed enhancement

Here's a first draft. Thanks @gvanrossum for sponsoring.

+248 -0

4 comments

1 changed file

brandtbucher

pr closed time in 13 days

pull request commentpython/peps

PEP 614: Relaxing Grammar Restrictions On Decorators

Ignoring the test failure, landing.

brandtbucher

comment created time in 13 days

pull request commentpython/peps

PEP 9999: Relaxing Grammar Restrictions On Decorators

Make it PEP 614 and I’ll merge it.

brandtbucher

comment created time in 14 days

pull request commentpython/cpython

Correct the documented default encoding

I think miss-islington got triggered multiple times.

@eric-wieser I expect this could be backported to earlier versions (3.8, 3.7) -- but I would want you to do a little research to make sure that the default is the same in those branches. (You can browse the branches online in GitHub.)

eric-wieser

comment created time in 14 days

push eventgvanrossum/cpython

Bonifacio de Oliveira

commit sha d47d0c8e9f2ca0f9f5d1bf0b35006a9a4d5ca684

Improve grammar in the import system reference documentation (GH-18209) Replaced the period with a comma. Automerge-Triggered-By: @Mariatta

view details

Shantanu

commit sha 2e6569b6692298fcc9aae0df3eb3181adb2a5099

bpo-39493: Fix definition of IO.closed in typing.py (#18265)

view details

Alex Henrie

commit sha 188bb5b1e868eecf2342195dc45caa332ac3b6c7

bpo-39494: Remove extra null terminators from kwlist vars (GH-18267)

view details

Victor Stinner

commit sha 5eb8bff7e4aa7e4d8580a30323641388c8ff59a5

bpo-38631: Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() (GH-18258) Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() in object.c and typeobject.c to also dump the involved Python object on a fatal error. It should ease debug when such fatal error occurs. If the double linked list is inconsistent, _Py_ForgetReference() no longer dumps previous and next objects in the fatal error, it now only dumps the current object. It ensures that the error message is displayed even if dumping the object does crash Python. Enhance _Py_ForgetReference() error messages; _PyObject_ASSERT_FAILED_MSG() logs the "_Py_ForgetReference" function name.

view details

Victor Stinner

commit sha 7a1f6c2da46a04d0ff0acc01542f30bfeaf0e0c7

bpo-38631: Avoid Py_FatalError() in init_slotdefs() (GH-18263) Rename init_slotdefs() to _PyTypes_InitSlotDefs() and add a return value of type PyStatus. The function is now called exactly once from _PyTypes_Init(). Replace calls to init_slotdefs() with an assertion checking that slotdefs is initialized.

view details

Victor Stinner

commit sha 2bf127d97bd1d60ead7c20d429b0c61ef61fc554

bpo-38631: Replace tp_new_wrapper() fatal error with SystemError (GH-18262) tp_new_wrapper() now raises a SystemError if called with non-type self, rather than calling Py_FatalError() which cannot be catched.

view details

Victor Stinner

commit sha c38fd0df2b4cbc1cc906d8dfe23f63b67cd6965f

bpo-39353: binascii.crc_hqx() is no longer deprecated (GH-18276) The binascii.crc_hqx() function is no longer deprecated.

view details

Alex Henrie

commit sha 1f44e775df8e7ec3ca60a1135cb3279f8b9dca3e

bpo-39497: Remove unused variable from pysqlite_cursor_executescript (GH-18271)

view details

damani42

commit sha 38c878b56cff997de8fb04a586c963039b69b414

bpo-39424: Use assertRaisesRegex instead of assertRaisesRegexp. (GH-18277)

view details

Victor Stinner

commit sha ec3c99c8a73650d7833189bd973ec492564aa479

bpo-38631: Avoid Py_FatalError() in unicodeobject.c (GH-18281) Replace Py_FatalError() calls with _PyErr_WriteUnraisableMsg(), _PyObject_ASSERT_FAILED_MSG() or Py_UNREACHABLE() in unicode_dealloc() and unicode_release_interned().

view details

Victor Stinner

commit sha 17c68b8107e348aeaaa05f7ac5072cacff916022

bpo-38631: Replace Py_FatalError() with assert() in ceval.c (GH-18279) Replace a few Py_FatalError() calls if tstate is NULL with assert(tstate != NULL) in ceval.c. PyEval_AcquireThread(), PyEval_ReleaseThread() and PyEval_RestoreThread() must never be called with a NULL tstate.

view details

Victor Stinner

commit sha 2a4903fcce54c25807d362dbbbcfb32d0b494f9f

bpo-38631: Add _Py_NO_RETURN to functions calling Py_FatalError() (GH-18278) Add _Py_NO_RETURN to functions calling Py_FatalError(): * _PyObject_AssertFailed() * dummy_dealloc() * faulthandler_fatal_error_thread() * none_dealloc() * notimplemented_dealloc()

view details

Dong-hee Na

commit sha 8d49f7ceb4f961770ae61fe6a4033c4e61cc3288

bpo-39434: Improve float __floordiv__ performance and error message (GH-18147)

view details

Victor Stinner

commit sha c232c9110cfefa0935cbf158e35e91746a8a9361

bpo-39502: Skip test_zipfile.test_add_file_after_2107() on AIX (GH-18282) Skip test_zipfile.test_add_file_after_2107() if time.localtime() fails with OverflowError. It is the case on AIX 6.1 for example.

view details

Hai Shi

commit sha 46874c26ee1fc752e2e6930efa1d223b2351edb8

bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254) Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.

view details

Zackery Spytz

commit sha bfdeaa37b3df7466624c17f9450d2bd1c3d95edf

bpo-38792: Remove IDLE shell calltip before new prompt. (#17150) Previously, a calltip might be left after SyntaxError, KeyboardInterrupt, or Shell Restart. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Tal Einat <taleinat+github@gmail.com>

view details

Julien Palard

commit sha 58a4054760bffbb20aff90290dd0f3554f7bea42

Doc: Fix s/pseudo random/pseudo-random/ (GH-18289)

view details

Kyle Stanley

commit sha f03a8f8d5001963ad5b5b28dbd95497e9cc15596

bpo-37224: Improve test__xxsubinterpreters.DestroyTests (GH-18058) Adds an additional assertion check based on a race condition for `test__xxsubinterpreters.DestroyTests.test_still_running` discovered in the bpo issue. https://bugs.python.org/issue37224

view details

Victor Stinner

commit sha 7dc140126e918cc7c6e65aea321b7255f0020798

bpo-39511: Fix multiprocessing semlock_acquire() (GH-18298) The Python C API must not be used when the GIL is released: only access Py_None when the GIL is hold.

view details

Victor Stinner

commit sha 4d96b4635aeff1b8ad41d41422ce808ce0b971c8

bpo-39511: PyThreadState_Clear() calls on_delete (GH-18296) PyThreadState.on_delete is a callback used to notify Python when a thread completes. _thread._set_sentinel() function creates a lock which is released when the thread completes. It sets on_delete callback to the internal release_sentinel() function. This lock is known as Threading._tstate_lock in the threading module. The release_sentinel() function uses the Python C API. The problem is that on_delete is called late in the Python finalization, when the C API is no longer fully working. The PyThreadState_Clear() function now calls the PyThreadState.on_delete callback. Previously, that happened in PyThreadState_Delete(). The release_sentinel() function is now called when the C API is still fully working.

view details

push time in 14 days

push eventgvanrossum/cpython

Bonifacio de Oliveira

commit sha d47d0c8e9f2ca0f9f5d1bf0b35006a9a4d5ca684

Improve grammar in the import system reference documentation (GH-18209) Replaced the period with a comma. Automerge-Triggered-By: @Mariatta

view details

Shantanu

commit sha 2e6569b6692298fcc9aae0df3eb3181adb2a5099

bpo-39493: Fix definition of IO.closed in typing.py (#18265)

view details

Alex Henrie

commit sha 188bb5b1e868eecf2342195dc45caa332ac3b6c7

bpo-39494: Remove extra null terminators from kwlist vars (GH-18267)

view details

Victor Stinner

commit sha 5eb8bff7e4aa7e4d8580a30323641388c8ff59a5

bpo-38631: Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() (GH-18258) Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() in object.c and typeobject.c to also dump the involved Python object on a fatal error. It should ease debug when such fatal error occurs. If the double linked list is inconsistent, _Py_ForgetReference() no longer dumps previous and next objects in the fatal error, it now only dumps the current object. It ensures that the error message is displayed even if dumping the object does crash Python. Enhance _Py_ForgetReference() error messages; _PyObject_ASSERT_FAILED_MSG() logs the "_Py_ForgetReference" function name.

view details

Victor Stinner

commit sha 7a1f6c2da46a04d0ff0acc01542f30bfeaf0e0c7

bpo-38631: Avoid Py_FatalError() in init_slotdefs() (GH-18263) Rename init_slotdefs() to _PyTypes_InitSlotDefs() and add a return value of type PyStatus. The function is now called exactly once from _PyTypes_Init(). Replace calls to init_slotdefs() with an assertion checking that slotdefs is initialized.

view details

Victor Stinner

commit sha 2bf127d97bd1d60ead7c20d429b0c61ef61fc554

bpo-38631: Replace tp_new_wrapper() fatal error with SystemError (GH-18262) tp_new_wrapper() now raises a SystemError if called with non-type self, rather than calling Py_FatalError() which cannot be catched.

view details

Victor Stinner

commit sha c38fd0df2b4cbc1cc906d8dfe23f63b67cd6965f

bpo-39353: binascii.crc_hqx() is no longer deprecated (GH-18276) The binascii.crc_hqx() function is no longer deprecated.

view details

Alex Henrie

commit sha 1f44e775df8e7ec3ca60a1135cb3279f8b9dca3e

bpo-39497: Remove unused variable from pysqlite_cursor_executescript (GH-18271)

view details

damani42

commit sha 38c878b56cff997de8fb04a586c963039b69b414

bpo-39424: Use assertRaisesRegex instead of assertRaisesRegexp. (GH-18277)

view details

Victor Stinner

commit sha ec3c99c8a73650d7833189bd973ec492564aa479

bpo-38631: Avoid Py_FatalError() in unicodeobject.c (GH-18281) Replace Py_FatalError() calls with _PyErr_WriteUnraisableMsg(), _PyObject_ASSERT_FAILED_MSG() or Py_UNREACHABLE() in unicode_dealloc() and unicode_release_interned().

view details

Victor Stinner

commit sha 17c68b8107e348aeaaa05f7ac5072cacff916022

bpo-38631: Replace Py_FatalError() with assert() in ceval.c (GH-18279) Replace a few Py_FatalError() calls if tstate is NULL with assert(tstate != NULL) in ceval.c. PyEval_AcquireThread(), PyEval_ReleaseThread() and PyEval_RestoreThread() must never be called with a NULL tstate.

view details

Victor Stinner

commit sha 2a4903fcce54c25807d362dbbbcfb32d0b494f9f

bpo-38631: Add _Py_NO_RETURN to functions calling Py_FatalError() (GH-18278) Add _Py_NO_RETURN to functions calling Py_FatalError(): * _PyObject_AssertFailed() * dummy_dealloc() * faulthandler_fatal_error_thread() * none_dealloc() * notimplemented_dealloc()

view details

Dong-hee Na

commit sha 8d49f7ceb4f961770ae61fe6a4033c4e61cc3288

bpo-39434: Improve float __floordiv__ performance and error message (GH-18147)

view details

Victor Stinner

commit sha c232c9110cfefa0935cbf158e35e91746a8a9361

bpo-39502: Skip test_zipfile.test_add_file_after_2107() on AIX (GH-18282) Skip test_zipfile.test_add_file_after_2107() if time.localtime() fails with OverflowError. It is the case on AIX 6.1 for example.

view details

Hai Shi

commit sha 46874c26ee1fc752e2e6930efa1d223b2351edb8

bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254) Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.

view details

Zackery Spytz

commit sha bfdeaa37b3df7466624c17f9450d2bd1c3d95edf

bpo-38792: Remove IDLE shell calltip before new prompt. (#17150) Previously, a calltip might be left after SyntaxError, KeyboardInterrupt, or Shell Restart. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Tal Einat <taleinat+github@gmail.com>

view details

Julien Palard

commit sha 58a4054760bffbb20aff90290dd0f3554f7bea42

Doc: Fix s/pseudo random/pseudo-random/ (GH-18289)

view details

Kyle Stanley

commit sha f03a8f8d5001963ad5b5b28dbd95497e9cc15596

bpo-37224: Improve test__xxsubinterpreters.DestroyTests (GH-18058) Adds an additional assertion check based on a race condition for `test__xxsubinterpreters.DestroyTests.test_still_running` discovered in the bpo issue. https://bugs.python.org/issue37224

view details

Victor Stinner

commit sha 7dc140126e918cc7c6e65aea321b7255f0020798

bpo-39511: Fix multiprocessing semlock_acquire() (GH-18298) The Python C API must not be used when the GIL is released: only access Py_None when the GIL is hold.

view details

Victor Stinner

commit sha 4d96b4635aeff1b8ad41d41422ce808ce0b971c8

bpo-39511: PyThreadState_Clear() calls on_delete (GH-18296) PyThreadState.on_delete is a callback used to notify Python when a thread completes. _thread._set_sentinel() function creates a lock which is released when the thread completes. It sets on_delete callback to the internal release_sentinel() function. This lock is known as Threading._tstate_lock in the threading module. The release_sentinel() function uses the Python C API. The problem is that on_delete is called late in the Python finalization, when the C API is no longer fully working. The PyThreadState_Clear() function now calls the PyThreadState.on_delete callback. Previously, that happened in PyThreadState_Delete(). The release_sentinel() function is now called when the C API is still fully working.

view details

push time in 14 days

pull request commentpython/cpython

bpo-3950: fix docs for default locale of gettext

Yup, the source is the same in 3.8, 3.7, 3.6. I did not search farther back.

Carl-Ty

comment created time in 14 days

pull request commentpython/cpython

bpo-3950: fix docs for default locale of gettext

I'm looking into whether this deserves backporting.

Carl-Ty

comment created time in 14 days

push eventpython/cpython

Carl

commit sha d68e0a8a165761604e820c8cb4f20abc735e717f

Issue3950: Fix docs for default locale used by gettext to match implementation (#18435) documentation for default locale directory Doc/library/gettext.rst changed to match gettext implementation line 63.

view details

push time in 14 days

PR merged python/cpython

bpo-3950: fix docs for default locale of gettext CLA signed awaiting merge skip news type-documentation

documentation for default locale directory in Doc/library/gettext.rst changed to match gettext implementation line 63.

<!-- issue-number: bpo-3950 --> https://bugs.python.org/issue3950 <!-- /issue-number -->

+2 -2

0 comment

1 changed file

Carl-Ty

pr closed time in 14 days

pull request commentpython/cpython

[3.6] bpo-39545: document that await does not work in f-strings

Sorry Larry and thanks Ned!

elenaoat

comment created time in 14 days

pull request commentpython/cpython

bpo-39545: document that await does not work in f-strings

This is waiting for @larryhastings to merge. This piece of documentation is only relevant for 3.6, since in 3.7 this actually works (see the issue, bpo-39545).

elenaoat

comment created time in 14 days

Pull request review commentgvanrossum/pegen

Add lookahead to simple_stmt rule

 small_stmt[stmt_ty]:     | &'global' global_stmt     | &'nonlocal' nonlocal_stmt compound_stmt[stmt_ty]:-    | &('@' | 'def' | ASYNC) function_def+    | &('def' | '@' | ASYNC) function_def

Clever!

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Add lookahead to simple_stmt rule

 atom[expr_ty]:     | &'[' list     | &'{' dict     | &'[' listcomp

I don't think so, because the lookahead ensures that we take exactly one path for each start character.

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 compound_stmt[stmt_ty]: function_def | if_stmt | class_def | with_stmt | for_stm  # NOTE: yield_expression may start with 'yield'; yield_expr must start with 'yield' assignment:-    | '(' a=ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {+    | '(' a=paren_ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 0, EXTRA)}     | a=ann_assign_target ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 1, EXTRA) }

D'oh. I had the sense of the flag backwards. :-(

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Add lookahead to simple_stmt rule

 atom[expr_ty]:     | &'[' list     | &'{' dict     | &'[' listcomp

Why not combine these three too?

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 compound_stmt[stmt_ty]: function_def | if_stmt | class_def | with_stmt | for_stm  # NOTE: yield_expression may start with 'yield'; yield_expr must start with 'yield' assignment:-    | '(' a=ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {+    | '(' a=paren_ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 0, EXTRA)}     | a=ann_assign_target ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 1, EXTRA) }

Hm, I tried this:

>>> ast.dump(ast.parse('(a):int'))
"Module(body=[AnnAssign(target=Name(id='a', ctx=Store()), annotation=Name(id='int', ctx=Load()), value=None, simple=0)], type_ignores=[])"
>>>

And this still comes up with simple=0 (no matter how many parens I put around it).

lysnikolaou

comment created time in 15 days

pull request commentgvanrossum/pegen

Correctly parse number literals

OK land it.

pablogsal

comment created time in 15 days

pull request commentgvanrossum/pegen

WIP: Add lookahead to simple_stmt rule

@apalala I would love your insights into optimizing the grammar!

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Correctly parse number literals

 dedent_token(Parser *p)     return expect_token(p, DEDENT); } +

These two functions are unchanged from ast.c right?

pablogsal

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 star_target[expr_ty]:     | star_atom star_atom[expr_ty]:     | a=NAME { set_expr_context(p, a, Store) }-    | '(' a=[star_target !','] ')' { set_expr_context(p, a, Store) }+    | '(' a=[star_target] ')' { set_expr_context(p, a, Store) }     | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) }     | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) } +paren_ann_assign_target[expr_ty]:+    | '(' a=paren_ann_assign_target ')' { a }+    | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }+    | a=t_primary b=slicing !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }+    | a=NAME { set_expr_context(p, a, Store) }+

Couldn't this just be

  | '(' a=paren_ann_assign_target ')' { a }
  | ann_assign_target

?

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 compound_stmt[stmt_ty]: function_def | if_stmt | class_def | with_stmt | for_stm  # NOTE: yield_expression may start with 'yield'; yield_expr must start with 'yield' assignment:-    | '(' a=ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {+    | '(' a=paren_ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 0, EXTRA)}     | a=ann_assign_target ':' b=expression c=['=' d=yield_expression { d }] {         _Py_AnnAssign(a, b, c, 1, EXTRA) }

These seem to be redundant except for the 0 or 1 argument to _Py_AnnAssign() -- and why do we need that? (I can't even figure out when simple=1 is ever set in an AST made by ast.parse()?)

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 star_target[expr_ty]:     | star_atom star_atom[expr_ty]:     | a=NAME { set_expr_context(p, a, Store) }+    | '(' a=[star_target !','] ')' { set_expr_context(p, a, Store) }     | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) }     | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) } +ann_assign_target[expr_ty]:+    | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }+    | a=t_primary b=slicing !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }+    | a=NAME { set_expr_context(p, a, Store) }+ del_targets[asdl_seq*]: a=','.del_target+ [','] { a } del_target[expr_ty]:     | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }     | a=t_primary b=slicing !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) }     | del_t_atom del_t_atom[expr_ty]:     | a=NAME { set_expr_context(p, a, Del) }-    | '(' b=[del_targets] ')' { _Py_Tuple(b, Del, EXTRA) }-    | '[' b=[del_targets] ']' { _Py_List(b, Del, EXTRA) }+    | '(' a=[del_target !','] ')' { set_expr_context(p, a, Del) }

I don't see why you need the !',' here, since you already have ')' following.

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 t_primary[expr_ty]: t_lookahead: '(' | '[' | '.' t_atom[expr_ty]:     | a=NAME { set_expr_context(p, a, Store) }+    | '(' a=[target !','] ')' { set_expr_context(p, a, Store) }

Ditto.

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 def f(*a, b): ]  FAIL_TEST_CASES = [+    ("annotation_multiple_targets", "(a, b): int = 42"),+    ("annotation_nested_tuple", "((a, b)): int"),

I'd ad (a,): int and a,: int

lysnikolaou

comment created time in 15 days

Pull request review commentgvanrossum/pegen

Fix bug with parenthesized targets and refactor assignment rule

 compound_stmt[stmt_ty]: function_def | if_stmt | class_def | with_stmt | for_stm  # NOTE: yield_expression may start with 'yield'; yield_expr must start with 'yield' assignment:-    | !'lambda' a=target ':' b=expression c=['=' d=yield_expression { d }] {-         _Py_AnnAssign(construct_assign_target(p, a), b, c,-         a->kind == Name_kind ? 1 : 0, EXTRA) }+    | '(' a=ann_assign_target ')' ':' b=expression c=['=' d=yield_expression { d }] {+        _Py_AnnAssign(a, b, c, 0, EXTRA)}+    | a=ann_assign_target ':' b=expression c=['=' d=yield_expression { d }] {+        _Py_AnnAssign(a, b, c, 1, EXTRA) }

If you can do a: int and (a): int then you can also do ((a)): int etc. (All of which IMO is stupid and only accepted due to a bug in the grammar but that's backwards compatibility for you.)

lysnikolaou

comment created time in 15 days

issue commentgvanrossum/pegen

Difference with parenthized del

Targets will be the death of us yet. :-)

ethanhs

comment created time in 15 days

issue commentgvanrossum/pegen

Integration into CPython

Thank you so much for doing this! This is immensely valuable. So far we've just tested with the stdlib, which clearly doesn't exercise every syntactic construct. (Also thanks @apalala for reminding us of the importance of doing this!)

gvanrossum

comment created time in 15 days

pull request commentgvanrossum/pegen

WIP: Add lookahead to simple_stmt rule

Yup, try this:

compound_stmt[stmt_ty]:
    | &('@' | 'def' | ASYNC) function_def
    | &'if' if_stmt
    | &('@' | 'class') class_def
    | &('with' | ASYNC) with_stmt
    | &('for' | ASYNC) for_stmt
    | &'try' try_stmt
    | &'while' while_stmt

Also, this might be a tad quicker:

return_stmt[stmt_ty]: 'return' a=[expressions] { _Py_Return(a, EXTRA) }

Together they move the median down to 5.255, IOW ~9% faster (before you idea!).

lysnikolaou

comment created time in 16 days

pull request commentgvanrossum/pegen

WIP: Add lookahead to simple_stmt rule

I betcha you can do a similar thing to compound_stmt for even more gain!

lysnikolaou

comment created time in 17 days

more