This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pydocs fails for some C implemented classes
Type: behavior Stage: resolved
Components: Interpreter Core, Tkinter Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Arfrever, Robin.Schreiber, amaury.forgeotdarc, asvetlov, benjamin.peterson, brett.cannon, eric.snow, ezio.melotti, loewis, ncoghlan, ned.deily, pitrou, python-dev, serhiy.storchaka, yselivanov
Priority: normal Keywords: 3.4regression, patch

Created on 2014-01-09 12:47 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_typespecs.patch serhiy.storchaka, 2014-01-09 12:47 Workaround for the _tkinter module review
type_from_spec_module.patch serhiy.storchaka, 2015-02-01 12:26 review
Messages (12)
msg207733 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-09 12:47
In 3.4 pydoc fails for the TkappType and TkttType names in the _tkinter module.

$ ./python -m pydoc _tkinter.TkappType
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/runpy.py", line 189, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/serhiy/py/cpython/Lib/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2593, in <module>
    cli()
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2558, in cli
    help.help(arg)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1840, in help
    elif request: doc(request, 'Help on %s:', output=self._output)
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1578, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1555, in render_doc
    module = inspect.getmodule(object)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 610, in getmodule
    file = getabsfile(object, _filename)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 593, in getabsfile
    _filename = getsourcefile(object) or getfile(object)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 569, in getsourcefile
    filename = getfile(object)
  File "/home/serhiy/py/cpython/Lib/inspect.py", line 519, in getfile
    object = sys.modules.get(object.__module__)
AttributeError: __module__

And same for _tkinter.TkttType.

This issue can be easy fixed for the _tkinter module, but general solution is needed, because pydoc in 3.4 still can be broken for third-party code.
msg208989 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-23 20:26
See issue #20372 -- fix for the 'inspect.getfile' function.
msg209003 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-23 21:47
With issue #20372 patch pydoc no longer raise an exception, but it also doesn't produce useful output. In 3.3 it prints more details.
msg231674 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-25 17:43
The problem not in pydoc or inspect itself. In Python 3.3 _tkinter.TkappType has the __module__ attribute:

>>> import _tkinter
>>> _tkinter.TkappType.__module__
'builtins'

Something was changed in 3.4 and builtin classes without dot in qualified name no longer have the __module__ attribute.
msg231695 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-26 07:48
_tkinter.TkappType.__flags__ is different.

In 3.3: 0b1000001000000000000
In 3.4: 0b1000001001000000000

The difference is Py_TPFLAGS_HEAPTYPE. This is the consequence of the change made in issue15721.
msg234269 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-01-18 20:11
I think we should add a check to ensure than heap types have the __module__ attribute.
msg235165 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-01 12:26
Here is a patch which adds a warning to PyType_FromSpec and PyType_FromSpecWithBases if type spec name doesn't contain module name. In conjunction with tkinter_typespecs.patch it should fix the issue.
msg236871 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-28 09:04
What type of warning is more preferable here? It will be emitted at import. E.g.:

$ ./python -Wall
Python 3.5.0a1+ (default:28ba862036cc+, Feb 28 2015, 11:01:23) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
_frozen_importlib:321: SyntaxWarning: builtin type tkapp has no the __module__ attribute
_frozen_importlib:321: SyntaxWarning: builtin type tktimertoken has no the __module__ attribute

DeprecationWarning? RuntimeWarning?
msg236879 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2015-02-28 11:44
The case for RuntimeWarning: the object isn't necessarily *broken* as such (most things will still work), but pickling and some introspection features may not work properly.

The case for DeprecationWarning: breaking picking and introspection is bad when the fix (setting __module__) is straightforward, so this should eventually become an AttributeError:

    AttributeError: __module__ not set on builtin type tkapp

My own preference is for the latter - eventually making it a hard requirement to specify the module name properly. Even true builtins officially live in the builtins module:

    >>> str.__module__
    'builtins'
msg236919 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-28 22:18
It also can be ImportWarning (warnings triggered during the process of importing a module (ignored by default)).
msg236936 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2015-03-01 06:34
ImportWarning is slightly different - it's aimed at issues that happen during the operation of the import machinery itself.

This isn't that - it's a warning related to the extension module actually initialising itself, so it's akin to a warning issued due to the behaviour of top level module source code, rather than by the import system.
msg236941 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-03-01 08:04
New changeset a192cc5a63be by Serhiy Storchaka in branch '3.4':
Issue #20204: Added the __module__ attribute to _tkinter classes.
https://hg.python.org/cpython/rev/a192cc5a63be

New changeset 3244142eeafb by Serhiy Storchaka in branch 'default':
Issue #20204: Added the __module__ attribute to _tkinter classes.
https://hg.python.org/cpython/rev/3244142eeafb

New changeset d6dff5a5290a by Serhiy Storchaka in branch 'default':
Issue #20204: Deprecation warning is now raised for builtin type without the
https://hg.python.org/cpython/rev/d6dff5a5290a
History
Date User Action Args
2022-04-11 14:57:56adminsetgithub: 64403
2015-03-19 07:25:59serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-03-01 11:58:22Arfreversetnosy: + Arfrever
2015-03-01 08:04:30python-devsetnosy: + python-dev
messages: + msg236941
2015-03-01 06:34:37ncoghlansetmessages: + msg236936
2015-02-28 22:18:31serhiy.storchakasetmessages: + msg236919
2015-02-28 11:44:43ncoghlansetmessages: + msg236879
2015-02-28 09:04:24serhiy.storchakasetpriority: high -> normal
nosy: + ezio.melotti
messages: + msg236871

2015-02-21 05:58:22serhiy.storchakasetnosy: + benjamin.peterson
2015-02-01 12:26:57serhiy.storchakasetfiles: + type_from_spec_module.patch

messages: + msg235165
stage: needs patch -> patch review
2015-01-18 20:11:08serhiy.storchakasetassignee: serhiy.storchaka
messages: + msg234269
stage: needs patch
2014-11-26 07:48:17serhiy.storchakasetversions: + Python 3.5
nosy: + loewis, amaury.forgeotdarc, pitrou, ned.deily, asvetlov, Robin.Schreiber

messages: + msg231695

components: + Interpreter Core, Tkinter
2014-11-25 17:43:34serhiy.storchakasetmessages: + msg231674
2014-01-23 21:47:19serhiy.storchakasetmessages: + msg209003
2014-01-23 20:26:51yselivanovsetmessages: + msg208989
2014-01-23 19:58:12serhiy.storchakasetnosy: + yselivanov
2014-01-09 12:51:23pitrousetpriority: normal -> high
nosy: + brett.cannon, ncoghlan, eric.snow
2014-01-09 12:47:35serhiy.storchakacreate