Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39481: WIP: PEP 585 #18239
bpo-39481: WIP: PEP 585 #18239
Conversation
}; | ||
|
||
static PyMemberDef ga_members[] = { | ||
{"__origin__", T_OBJECT, offsetof(gaobject, origin), READONLY}, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
gvanrossum
Jan 28, 2020
Author
Member
I think not. The two attributes should never be allowed to be NULL. (This is a change from an earlier design.)
static PyObject * | ||
ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||
{ | ||
if (kwds != NULL) { |
This comment has been minimized.
This comment has been minimized.
serhiy-storchaka
Jan 28, 2020
Member
It is worth to use Argument Clinic which generates simpler code using non-public C API similar to the following:
if (!_PyArg_NoKeywords("GenericAlias", kwds) ||
!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2))
{
return NULL;
}
}; | ||
|
||
static PyObject * | ||
ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
gvanrossum
Jan 28, 2020
Author
Member
I first had a tp_init. Then calling GenericAlias() somehow worked and produced an object with NULL attributes (or maybe it was some more clever incantation, I forget, but I definitely saw it). I do want the class instantiable from Python (so it can potentially be used from typing.py). Using tp_new instead solved that problem.
This comment has been minimized.
This comment has been minimized.
So I'm looking into the test failures. I've fixed two simple ones, but now I'm stuck with at least two:
The problem with test_typing.py is that when we have a class that derives from
its MRO contains |
This comment has been minimized.
This comment has been minimized.
Using a debug build I can repro the test_genericalias.py crash. The upper few lines of the stack trace are:
@ethanhs does this give you a clue? Methinks there's a refcount bug in ga_repr(). :-( |
This comment has been minimized.
This comment has been minimized.
@ethanhs Update: it's crashing in |
This comment has been minimized.
This comment has been minimized.
Okay, so test_typing.py is the only failing test (see above). But I think the gc_repr() code might be refactored a bit to avoid getting the |
This comment has been minimized.
This comment has been minimized.
Ah, are you suggesting that we move those into the branch where we check fro (also thank you for fixing the crash!) |
|
||
class BaseTest(unittest.TestCase): | ||
"""Test basics.""" | ||
|
||
def test_subscriptable(self): | ||
for t in tuple, list, dict, set, frozenset, defaultdict, deque: | ||
for t in tuple, list, dict, set, frozenset, defaultdict, deque, IOBase, Pattern, Match: |
This comment has been minimized.
This comment has been minimized.
serhiy-storchaka
Jan 29, 2020
Member
TODO: I suppose IOBase subclasses BufferedIOBase, RawIOBase and TextIOBase should not support indexing.
This comment has been minimized.
This comment has been minimized.
serhiy-storchaka
Jan 29, 2020
Member
There is also Python implementation _pyio.IOBase
. I am not sure what to do with it. Maybe just ignore for now.
This comment has been minimized.
This comment has been minimized.
gvanrossum
Jan 29, 2020
•
Author
Member
I added __class_getitem__
to _pyio.IOBase
in 35cd5f4.
I'm not sure whether it matters much that we take the __class_getitem__
away from the various subclasses (let the static type checkers worry about that).
This comment has been minimized.
This comment has been minimized.
These are temporary hacks -- once I have eq working this should be excised. |
However, dict[T, int][str] -> dict[str], which is wrong! Similar, dict[T, T][str] fails but should return dict[str, str]. Finally, dict[T, T].__parameters__ -> (T, T) but should be (T,).
Also move declaration of Py_GenericAliasType to descrobject.h.
…generic_rules_subclassing
This comment has been minimized.
This comment has been minimized.
@serhiy-storchaka Can you review again? A lot has changed. (See also python/peps#1289.) |
This comment has been minimized.
This comment has been minimized.
codecov
bot
commented
Jan 31, 2020
Codecov Report
@@ Coverage Diff @@
## master #18239 +/- ##
==========================================
- Coverage 82.20% 82.12% -0.08%
==========================================
Files 1957 1955 -2
Lines 589079 583703 -5376
Branches 44401 44407 +6
==========================================
- Hits 484247 479380 -4867
+ Misses 95174 94681 -493
+ Partials 9658 9642 -16
Continue to review full report at Codecov.
|
gvanrossum commentedJan 28, 2020
•
edited by bedevere-bot
https://bugs.python.org/issue39481