Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDocumentation confusion - implicit vs explicit declaration #226
Comments
|
According to PEP 526, the first form of attribute declaration should actually be treated as instance membership as opposed to class membership by the type checker. If you explicitly want class membership, you'll need to use class Derp:
instance_attribute: int = 1 # instance membership
class_attribute: ClassVar[int] = 1 # class membershipI don' t think Pyre currently fully enforce this distinction, but we might eventually go there in the future as I feel there's value in explicitly distinguishing between instance members and class members. The fact that |
|
Yeah, it does seem unfortunate. class Foo:
x: int
def __init__():
self.x = 10As opposed to the implicit one: class Foo:
def __init__():
self.x : int = 10 |
The documentation equates two kinds of attribute declarations:
explicit:
and implicit:
Those two things are not about explicit vs implicit declaration, but about class membership (static field) vs member field.
I think it's worth changing the doc to avoid confusion.
Example of difference: