Skip to content

Reference implementation of __class_getitem__ and __mro_entries__ #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 220 commits into from

Conversation

ilevkivskyi
Copy link
Owner

This is a very simple implementation of the idea discussed in python/typing#432

@codecov-io
Copy link

codecov-io commented Jul 19, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@e184cfd). Click here to learn what that means.
The diff coverage is 93.91%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master       #2   +/-   ##
=========================================
  Coverage          ?   82.58%           
=========================================
  Files             ?     1444           
  Lines             ?   359957           
  Branches          ?        0           
=========================================
  Hits              ?   297285           
  Misses            ?    62672           
  Partials          ?        0
Impacted Files Coverage Δ
Lib/types.py 98.3% <100%> (ø)
Lib/test/test_types.py 96.77% <100%> (ø)
Lib/test/test_genericclass.py 92% <92%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e184cfd...7cc8d8f. Read the comment docs.

@ilevkivskyi ilevkivskyi changed the title POC implementation of __base_subclass__ POC implementation of __class_getitem__ and __subclass_base__ Sep 9, 2017
@ilevkivskyi ilevkivskyi changed the title POC implementation of __class_getitem__ and __subclass_base__ Reference implementation of __class_getitem__ and __subclass_base__ Sep 10, 2017
@@ -168,6 +169,25 @@ PyObject_GetItem(PyObject *o, PyObject *key)
"be integer, not '%.200s'", key);
}

if (PyType_Check(o)) {
meth = PyObject_GetAttrString(o, "__class_getitem__");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use a Py_IDENTIFIER.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when making an actual PR to python/cpython I will probably switch to _PyObject_GetAttrId.

@ilevkivskyi ilevkivskyi changed the title Reference implementation of __class_getitem__ and __subclass_base__ Reference implementation of __class_getitem__ and __mro_entry__ Nov 11, 2017
vstinner and others added 29 commits December 1, 2017 20:09
…#4667)

Changes:

* _PyPathConfig_Fini() cannot be called in Py_FinalizeEx().
  Py_Initialize() and Py_Finalize() can be called multiple times, but
  it must not "forget" parameters set by Py_SetProgramName(),
  Py_SetPath() or Py_SetPythonHome(), whereas _PyPathConfig_Fini()
  clear all these parameters.
* config_get_program_name() and calculate_program_full_path() now
  also decode paths using Py_DecodeLocale() to use the
  surrogateescape error handler, rather than decoding using
  mbstowcs() which is strict.
* Change _Py_CheckPython3() prototype: () => (void)
* Truncate a few lines which were too long
* Factorize code from PC/getpathp.c and Modules/getpath.c to remove
  duplicated code
* rename pathconfig_clear() to _PyPathConfig_Clear()
* Inline _PyPathConfig_Fini() in pymain_impl() and then remove it,
  since it's a oneliner
_PyPathConfig_Init() now also initialize home and program_name:

* Rename existing _PyPathConfig_Init() to _PyPathConfig_Calculate().
  Add a new _PyPathConfig_Init() function in pathconfig.c which
  handles the _Py_path_config variable and call
  _PyPathConfig_Calculate().
* Add home and program_name fields to _PyPathConfig.home
* _PyPathConfig_Init() now initialize home and program_name
  from main_config
* Py_SetProgramName(), Py_SetPythonHome() and Py_GetPythonHome() now
  calls Py_FatalError() on failure, instead of silently ignoring
  failures.
* config_init_home() now gets directly _Py_path_config.home to only
  get the value set by Py_SetPythonHome(), or NULL if
  Py_SetPythonHome() was not called.
* config_get_program_name() now gets directly
  _Py_path_config.program_name to only get the value set by
  Py_SetProgramName(), or NULL if Py_SetProgramName() was not called.
* pymain_init_python() doesn't call Py_SetProgramName() anymore,
  _PyPathConfig_Init() now always sets the program name
* Call _PyMainInterpreterConfig_Read() in
  pymain_parse_cmdline_envvars_impl() to control the memory allocator
* C API documentation: it's no more safe to call Py_GetProgramName()
  before Py_Initialize().
…0. (python#4681)

* Revert "bpo-32030: _PyPathConfig_Init() sets home and program_name (python#4673)"

This reverts commit af5a895.

* Revert "bpo-32030: Fix config_get_program_name() on macOS (python#4669)"

This reverts commit e23c06e.

* Revert "bpo-32030: Add Python/pathconfig.c (python#4668)"

This reverts commit 0ea395a.

* Revert "bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (python#4667)"

This reverts commit ebac19d.

* Revert "bpo-32030: Fix Py_GetPath(): init program_name (python#4665)"

This reverts commit 9ac3d88.
If the marshal or bytecode formats get changed, frozen.c needs to
be updated as well.  It can be easy to miss this step and not doing
so can cause test_importlib to crash in mysterious ways.  Add an
explict unit test to make it easier to track down the problem.
…3940)

Also addresses doc build failures documented in bpo-32200.
Previously, CO_NOFREE was set in the compiler, which meant
it could end up being set incorrectly when code objects
were created directly. Setting it in the constructor based
on freevars and cellvars ensures it is always accurate,
regardless of how the code object is defined.
Add import_find_and_load() helper function.  The addition of
the importtime option has made PyImport_ImportModuleLevelObject() large
and so using a helper seems worthwhile.  It also makes it clearer that
abs_name is the only argument needed by _find_and_load().
…python#4570)

instead of crashing due to a stack overflow.

This perhaps will fix similar problems in other extension types.
The original algorithm tried to delegate the folding to the tokens so
that those tokens whose folding rules differed could specify the
differences.  However, this resulted in a lot of duplicated code because
most of the rules were the same.

The new algorithm moves all folding logic into a set of functions
external to the token classes, but puts the information about which
tokens can be folded in which ways on the tokens...with the exception of
mime-parameters, which are a special case (which was not even
implemented in the old folder).

This algorithm can still probably be improved and hopefully simplified
somewhat.

Note that some of the test expectations are changed.  I believe the
changes are toward more desirable and consistent behavior: in general
when (re) folding a line the canonical version of the tokens is
generated, rather than preserving errors or extra whitespace.
uuid.get_node() always must return a stable result.
Also added a test for non-reproducibility of _random_getnode().
Original patch by Xavier de Gaye.
…rns. (python#4471)

Also fixed searching patterns that could match an empty string.
…bpo-32030. (python#4681)" (python#4694)

* Revert "bpo-32197: Try to fix a compiler error on OS X introduced in bpo-32030. (python#4681)"

This reverts commit 13badcb.

Re-apply commits:

* "bpo-32030: _PyPathConfig_Init() sets home and program_name (python#4673)"
  commit af5a895.
* "bpo-32030: Fix config_get_program_name() on macOS (python#4669)"
  commit e23c06e.
* "bpo-32030: Add Python/pathconfig.c (python#4668)"
  commit 0ea395a.
* "bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (python#4667)"
  commit ebac19d.
* "bpo-32030: Fix Py_GetPath(): init program_name (python#4665)"
  commit 9ac3d88.

* Fix compilation error on macOS
Patches are in 3.7.0a3 even if this update is not.
When tk event handling is driven by IDLE's run loop, a confusing
and distracting queue.EMPTY traceback context is no longer added
to tk event exception tracebacks.  The traceback is now the same
as when event handling is driven by user code.  Patch based on
a suggestion by Serhiy Storchaka.
…to some fields (python#4685)

* Rather than raise TypeError, warn and call list() on the value.

* Fix tests, revise NEWS and whatsnew text.

* Revise documentation, a string is okay as well.

* Ensure 'requires' and 'obsoletes' are real lists.

* Test that requires and obsoletes are turned to lists.
…hon#4720)

The undecodable file name cannot be created on macOS APFS file systems.
* Simplify _PyCoreConfig_INIT, _PyMainInterpreterConfig_INIT,
  _PyPathConfig_INIT macros: no need to set fields to 0/NULL, it's
  redundant (the C language sets them to 0/NULL for us).
* Fix typo: pymain_run_statup() => pymain_run_startup()
* Remove a few XXX/TODO
@ilevkivskyi ilevkivskyi closed this Dec 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.