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

Faulty flattening logic #10

Open
Tirasz opened this issue Apr 19, 2022 · 2 comments
Open

Faulty flattening logic #10

Tirasz opened this issue Apr 19, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Tirasz
Copy link
Owner

Tirasz commented Apr 19, 2022

This:

if isinstance(channel, (Thread, TextChannel)) and guild is not None:
    member = guild.get_member(user_id)
    if member is None:
        member_data = data.get('member')
        if member_data:
            member = Member(data=member_data, state=self, guild=guild)

Got turned into this:

match channel:
    case Thread() | TextChannel() if guild is not None and member is None:
        member = guild.get_member(user_id)
        member_data = data.get('member')
        if member_data:
            member = Member(data=member_data, state=self, guild=guild)

Im not 100% sure, but i think this is because the nested if-node doesnt have an "else:" block, thus there is no case created for when only the main if-node's test is true, which is a pretty big oversight.
Possible fixes:

  • only flatten if the nested node has else block
  • or, always create a case where only the parents test is transformed?
@Tirasz
Copy link
Owner Author

Tirasz commented Apr 19, 2022

What is happening in a simpler example:

if A == 2 and C:
    pre_nest()
    if B == 3:
        nested()

if A == 2 and C: 
    pre_nest()
    if B == 3:
        nested()
    else:
        nested_else()
    

Gets turned into:

match A:
    case 2 if C and B == 3:
        pre_nest()
        nested()

match A:
    case 2 if C and B == 3:
        pre_nest()
        nested()
    case 2:
        pre_nest()
        nested_else()
    

Many things are wrong with this but im too tired

@Tirasz Tirasz added the bug Something isn't working label Apr 29, 2022
@Tirasz
Copy link
Owner Author

Tirasz commented Jul 4, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant