9b0169be35
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 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`.
33 lines
796 B
Python
33 lines
796 B
Python
# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
|
|
|
|
"""An example program that should be Pylint clean"""
|
|
|
|
import binascii
|
|
import os
|
|
import pulumi
|
|
from pulumi.dynamic import Resource, ResourceProvider, CreateResult
|
|
|
|
|
|
class RandomResourceProvider(ResourceProvider):
|
|
"""Random resource provider."""
|
|
|
|
def create(self, props):
|
|
val = binascii.b2a_hex(os.urandom(15)).decode("ascii")
|
|
return CreateResult(val, {"val": val})
|
|
|
|
|
|
class Random(Resource):
|
|
"""Random resource."""
|
|
val: str
|
|
|
|
def __init__(self, name, opts=None):
|
|
super().__init__(RandomResourceProvider(), name, {"val": ""}, opts)
|
|
|
|
|
|
r = Random("foo")
|
|
|
|
pulumi.export("cwd", os.getcwd())
|
|
pulumi.export("random_urn", r.urn)
|
|
pulumi.export("random_id", r.id)
|
|
pulumi.export("random_val", r.val)
|