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

union types as 'X | Y' not detected sometimes #159

Closed
grische opened this issue Mar 6, 2023 · 2 comments · Fixed by #174
Closed

union types as 'X | Y' not detected sometimes #159

grische opened this issue Mar 6, 2023 · 2 comments · Fixed by #174

Comments

@grische
Copy link

grische commented Mar 6, 2023

Describe the bug
union types as 'X | Y' not detected under some circumstances.

To Reproduce

#!/usr/bin/python3

import ipaddress


def function(argument: ipaddress.IPv4Interface | ipaddress.IPv6Interface):
    if isinstance(argument, ipaddress.IPv4Address):
        print("We got an IPv4")
    elif isinstance(argument, ipaddress.IPv6Address):
        print("We got an IPv6")
    else:
        print(f"We got type {type(argument)}")


function(ipaddress.ip_address("169.254.0.1"))
function(ipaddress.ip_address("fe80::1"))
function(True)

but vermin does not detect this:

$ vermin -vvvv test.py
Detecting python files..
Analyzing using 8 processes..
!2, 3.6      /tmp/test.py
  print(expr) requires 2.0, 3.0
  L3 C7: 'ipaddress' module requires !2, 3.3
  L6: annotations require !2, 3.0
  L12: f-strings require !2, 3.6
  L12 C29: 'type' member requires 2.2, 3.0
  L15: Ignoring member 'function' because it's user-defined!
  L16: Ignoring member 'function' because it's user-defined!
  L17: Ignoring member 'function' because it's user-defined!

Tips:
- You're using potentially backported modules: ipaddress
  If so, try using the following for better results: --backport ipaddress
- Since '# novm' or '# novermin' weren't used, a speedup can be achieved using: --no-parse-comments
(disable using: --no-tips)

Minimum required versions: 3.6
Incompatible versions:     2

Expected behavior
I expected vermin to detect L6: union types as 'X | Y' require !2, 3.10.

Environment (please complete the following information):

  • Vermin version: 1.5.1
@netromdk
Copy link
Owner

netromdk commented Apr 7, 2023

Thank you for reporting this. And sorry for the slow reply!

I'm looking into it and found a fix for it. The problem is that it's currently very difficult to sort the true and false positive matches. This has also been discussed in other issues, like #103, where we might need to make this detection opt-in.

@netromdk
Copy link
Owner

netromdk commented Apr 7, 2023

I've added a fix nonetheless because it didn't properly detect union types when ast.Attribute were in play, only ast.Name and None types. This needs to get in even if we later make the detection opt-in.

Detecting python files..
Analyzing using 10 processes..
!2, 3.10     test.py
  print(expr) requires 2.0, 3.0
  L3 C7: 'ipaddress' module requires !2, 3.3
  L6: annotations require !2, 3.0
  L6: union types as `X | Y` require !2, 3.10
  L12: f-strings require !2, 3.6
  L12 C29: 'type' member requires 2.0, 3.0
  L15: Ignoring member 'function' because it's user-defined!
  L16: Ignoring member 'function' because it's user-defined!
  L17: True/False constant requires 2.3, 3.0
  L17: Ignoring member 'function' because it's user-defined!

Tips:
- You're using potentially backported modules: ipaddress
  If so, try using the following for better results: --backport ipaddress
- Since '# novm' or '# novermin' weren't used, a speedup can be achieved using: --no-parse-comments
(disable using: --no-tips)

Minimum required versions: 3.10
Incompatible versions:     2

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

Successfully merging a pull request may close this issue.

2 participants