nac3core: add fields initialization check for parent class #310

Open
z78078 wants to merge 1 commits from issue-136 into master

Field initialization checks for case below would be available.

class Foo:
    x: int32
    z: int32

    def __init__(self,):
        self.x = 42
        self.z = 43


class Bar(Foo):
    y: int32

    def __init__(self,):
        self.y = 41


class Baz(Bar):
    def __init__(self,):
        pass


def run() -> int32:
    b = Bar()
    return 0

Field initialization checks for case below would be available. ``` class Foo: x: int32 z: int32 def __init__(self,): self.x = 42 self.z = 43 class Bar(Foo): y: int32 def __init__(self,): self.y = 41 class Baz(Bar): def __init__(self,): pass def run() -> int32: b = Bar() return 0 ```
z78078 added 1 commit 2022-08-17 17:46:24 +08:00
sb10q requested review from ychenfo 2022-08-24 16:59:22 +08:00
Collaborator

This looks good to me! The only thing that might be of a bit concern is that this deviates from python's original semantic, under which the following code would give an error.

But I think the python's original semantic is due to its dynamic nature, in nac3 we are doing things more statically so this should be fine if our users are aware of the behavior of nac3.

class A:
	def __init__(self):
    	self.a = 4
class B(A):
	def __init__(self):
    	self.b = 5

b = B()
b.a      # error: has no attribute 'a'
This looks good to me! The only thing that might be of a bit concern is that this deviates from python's original semantic, under which the following code would give an error. But I think the python's original semantic is due to its dynamic nature, in nac3 we are doing things more statically so this should be fine if our users are aware of the behavior of nac3. ```python class A: def __init__(self): self.a = 4 class B(A): def __init__(self): self.b = 5 b = B() b.a # error: has no attribute 'a' ```
This pull request has changes conflicting with the target branch.
  • nac3core/src/toplevel/composer.rs
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b issue-136 master
git pull origin issue-136

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff issue-136
git push origin master
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#310
There is no content yet.