Skip to content

Infer completions from __getattr__ literals - #5415

Open
Flpvoigt wants to merge 1 commit into
meta:mainfrom
Flpvoigt:flpvoigt/getattr-literal-completions
Open

Flpvoigt wants to merge 1 commit into
meta:mainfrom
Flpvoigt:flpvoigt/getattr-literal-completions

Conversation

@Flpvoigt

Copy link
Copy Markdown

Summary

Pyrefly previously did not provide completion suggestions for attributes dynamically handled by __getattr__.

This change reads the string literals from the parameter after self. For example, when the parameter is annotated with Literal["A", "B"], Pyrefly suggests A and B as attribute completions while avoiding duplicates with attributes already defined on the class.

Fixes #5312

Original description in Portuguese

Foi implementado o autocomplete de atributos definidos dinamicamente pelo __getattr__.

Antes, neste código:

from typing import Literal

class A:
    def __getattr__(self, item: Literal["A", "B"]) -> object: ...

A().

o Pyrefly não sugeria nada relacionado ao Literal.

Agora ele:

- encontra o método __getattr__;
- identifica o parâmetro depois de self;
- lê os valores de Literal["A", "B"];
- oferece A e B no autocomplete;
- evita repetir nomes que já sejam atributos reais da classe.
</details>

- [ ] I am a human, and I fully understand the code I am submitting.

# Test Plan

- Added a language server completion test for Literal["A", "B"].
- Ran cargo test -p pyrefly --lib dot_complete_from_getattr_literal_parameter --jobs 1.
- Result: 1 passed; 0 failed.

@meta-cla

meta-cla Bot commented Oct 27, 2026

Copy link
Copy Markdown

Hi @Flpvoigt!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@rchen152

Copy link
Copy Markdown
Contributor

Thanks @Flpvoigt! Could you please sign our CLA: https://code.facebook.com/cla? After that, we'll be able to review this PR (and any others going forward).

@meta-cla

meta-cla Bot commented Oct 28, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infer code completion of __getattr__

3 participants