Skip to content

False negative global-variable-not-assigned (while respective functional test passes correctly) #1375

@eight04

Description

@eight04

Steps to reproduce

Try to lint following code:

a = 1
def foo():
	global a
	print(a)

Current behavior

No config file found, using default configuration
************* Module test
W:  3, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  4, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Invalid constant name "a" (invalid-name)
C:  2, 0: Black listed name "foo" (blacklisted-name)
C:  2, 0: Missing function docstring (missing-docstring)
C:  3, 1: Invalid constant name "a" (invalid-name)
W:  3, 1: Using the global statement (global-statement)

Expected behavior

W:  3, 1: Using global for 'a' but no assignment is done (global-variable-not-as
signed)

pylint --version output

pylint 1.7.0,
astroid 1.5.0
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (In
tel)]

It is reported correctly in pylint 1.6.5.

No config file found, using default configuration
************* Module test
W:  3, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  4, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Invalid constant name "a" (invalid-name)
C:  2, 0: Black listed name "foo" (blacklisted-name)
C:  2, 0: Missing function docstring (missing-docstring)
W:  3, 1: Using global for 'a' but no assignment is done (global-variable-not-as
signed)
C:  3, 1: Invalid constant name "a" (invalid-name)
__main__.py 1.6.5,
astroid 1.4.9
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 15:51:26) [MSC v.1900 32 bit (In
tel)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲False Negative 🦋No message is emitted but something is wrong with the code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions