Skip to content
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

getting a class source regresses in Python 3.9 #86832

Open
t-vi mannequin opened this issue Dec 17, 2020 · 2 comments
Open

getting a class source regresses in Python 3.9 #86832

t-vi mannequin opened this issue Dec 17, 2020 · 2 comments
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@t-vi
Copy link
Mannequin

t-vi mannequin commented Dec 17, 2020

BPO 42666
Nosy @t-vi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-12-17.09:06:46.854>
labels = ['type-bug', 'library', '3.9', '3.10']
title = 'getting a class source regresses in Python 3.9'
updated_at = <Date 2020-12-17.09:11:37.904>
user = 'https://github.com/t-vi'

bugs.python.org fields:

activity = <Date 2020-12-17.09:11:37.904>
actor = 't-vi'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-12-17.09:06:46.854>
creator = 't-vi'
dependencies = []
files = []
hgrepos = []
issue_num = 42666
keywords = []
message_count = 2.0
messages = ['383223', '383224']
nosy_count = 1.0
nosy_names = ['t-vi']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42666'
versions = ['Python 3.9', 'Python 3.10']

@t-vi
Copy link
Mannequin Author

t-vi mannequin commented Dec 17, 2020

getting a class source regresses in Python 3.9 onwards.
The following worked in Python 3.8, now it doesn't anymore for 3.9.1 and 3.10.0a2:

(save as foo.py)

import inspect

class Foo:
    def spam(self):
        global Bar
        class Bar:
            pass
        print(inspect.getsource(Bar))

Foo().spam()

It seems that getsource is very brittle for classes.

@t-vi t-vi mannequin added 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 17, 2020
@t-vi
Copy link
Mannequin Author

t-vi mannequin commented Dec 17, 2020

I might add that this is a case I hit in the PyTorch test suite.

I tried to fix this a long time ago in a pricipled way in
https://bugs.python.org/issue33826

and Guido explained that fixing it was too heavy handed to be worthwile in

https://mail.python.org/archives/list/python-dev@python.org/thread/AC5B5VORS6FF6KJ3EG5DIV3ZLAQB6DIY/#UL376F3Y6FKJUZ2HZDA3ERFUDDOX67X4

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants