Skip to content

Promote literals in unannotated module globals #1822

@JanFontanet

Description

@JanFontanet

Summary

I've a 3rd party library that exposes some configuration through module variables, so I've to overwrite them in order for the library to work as I want. But when I run ty check on my code I got an error that can be reproduced with the minimal example below.

a.py:

MY_VAR=1

main.py

import a

a.MY_VAR=2

I got the following error:

Object of type `Literal[2]` is not assignable to attribute `MY_VAR` of type `Literal[1]` (invalid-assignment) [Ln 3, Col 1]

Version

ty 0.0.1-alpha.32

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions