Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint(no-member) when accessing resource.id #4813

Merged
merged 3 commits into from
Jun 12, 2020
Merged

Conversation

justinvp
Copy link
Member

Pylint currently reports E1101: Instance of 'Bucket' has no 'id' member (no-member) on lines in Pulumi Python programs like:

pulumi.export('bucket_name', bucket.id)

Here's a description of this message from http://pylint-messages.wikidot.com/messages:e1101:

Used when an object (variable, function, …) is accessed for a non-existent member.

False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.

This appears to be a false positive case: id isn't set in the constructor (it's set later in register_resource) and Pylint isn't able to figure this out statically. urn has the same problem. (Oddly, Pylint doesn't complain when accessing other resource output properties).

This change refactors register_resource so that id and urn can be assigned in the resource's constructor, so that Pylint can see it being assigned. The change also does the same with read_resource.

Fixes #3765

Pylint currently reports `E1101: Instance of 'Bucket' has no 'id' member (no-member)` on lines in Pulumi Python programs like:

```python
pulumi.export('bucket_name', bucket.id)
```

Here's a description of this message from http://pylint-messages.wikidot.com/messages:e1101:

> Used when an object (variable, function, …) is accessed for a non-existent member.
>
> False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.

This is a false positive because `id` isn't set in the initializer method, it's set later in `register_resource` and Pylint isn't able to figure this out statically.

This change refactors `register_resource` so that `id` (and `urn`) can be assigned in the resource's initializer, so that Pylint can see it being assigned, and does the same for `read_resource`.
@justinvp justinvp merged commit 9b0169b into master Jun 12, 2020
@pulumi-bot pulumi-bot deleted the justin/pylint branch June 12, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python: pylint(no-member) error on Resource.id
2 participants