Skip to content

'Constant name doesn't conform' warning on global statement instead of declaration #8307

@macdjord

Description

@macdjord

Bug description

import typing as _tp

_foo: _tp.Optional["Foo"] = None


class Foo:
    ...


def setup_shared_foo():
    global _foo

    _foo = Foo()

Configuration

No response

Command used

pylint test.py

Pylint output

test.py:11:4: C0103: Constant name "_foo" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern) (invalid-name)

Expected behavior

Pylint should warn about the 'incorrect' variable name on line 3, where the variable is defined, not line 11, where it is used in a global statement.

Pylint version

pylint 2.16.2
astroid 2.14.2
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Windows 10

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

Bug 🪲Needs PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions