[New-bugs-announce] [issue38752] __init__ taking out of context variables

Sebastian Bevc report at bugs.python.org
Fri Nov 8 20:07:28 EST 2019


New submission from Sebastian Bevc <sebastian.bevc at gmail.com>:

Hello,

This is my first bug report. While doing some homework i came to realize that the __init__ of a class was taking out of context variables.

class Foo(object):
  def __init__(self, attr1):
    self.out_of_context = out_of_context


# Raises NameError as it is expected
foo = Foo('some attr')

# 'bar' is bounded to 'out_of_context' although it was initialized
# with value 'some value'
out_of_context = 'bar'
foo = Foo('some value')
print(foo.out_of_context')  # prints 'bar'

----------
components: asyncio
messages: 356277
nosy: asvetlov, sebasbeco, yselivanov
priority: normal
severity: normal
status: open
title: __init__ taking out of context variables
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38752>
_______________________________________


More information about the New-bugs-announce mailing list