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

unexpected context behaviour #173

Closed
bitplorer opened this issue May 8, 2023 · 4 comments
Closed

unexpected context behaviour #173

bitplorer opened this issue May 8, 2023 · 4 comments

Comments

@bitplorer
Copy link

bitplorer commented May 8, 2023

Here is a minimal code

def subcontext(*args):
    with div("sub context") as _subcontext:
        _subcontext.add(*args)
    return  _subcontext

with div("context") as context_1:
    subcontext(div("inside subcontext"))

with div("context") as context_2:
    inside_context_and_hello = div("inside context and subcontext")
    subcontext(inside_context_and_hello)

print(context_1)
print(context_2)

expected context_1 output :

<div>
  context
  <div>
    sub context
    <div>
      inside subcontext
    </div>
  </div>
</div>

actual context_1 output:

<div>
  context
  <div>
    inside subcontext
  </div>
  <div>
    sub context
    <div>
      inside subcontext
    </div>
  </div>
</div>

while context_2 actual output is same as expected:

<div>
  context
  <div>
    inside context and subcontext
  </div>
  <div>
    sub context
    <div>
      inside context and subcontext
    </div>
  </div>
</div>

how should context behaviour be changed ?

@Knio
Copy link
Owner

Knio commented May 20, 2023

that does seem weird. what is _hello on line 4?

@Knio Knio closed this as completed in f43a9ca May 20, 2023
@Knio
Copy link
Owner

Knio commented May 20, 2023

case 1 is fixed.
case 2 i do not believe should have different behaviour than case 1. if you want a node to be added twice, it should be explicit with .add() in both places

@bitplorer
Copy link
Author

Thanks !

@Knio
Copy link
Owner

Knio commented May 21, 2023

published 2.8.0

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

No branches or pull requests

2 participants