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

parse_ip_network now accepts new HOSTMASK flag #376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

claytonsingh
Copy link
Contributor

Resolves #123

@codecov-commenter
Copy link

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (625a780) 85.72% compared to head (53b8974) 86.01%.
Report is 11 commits behind head on master.

Files Patch % Lines
netaddr/ip/__init__.py 66.66% 2 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #376      +/-   ##
==========================================
+ Coverage   85.72%   86.01%   +0.28%     
==========================================
  Files          47       47              
  Lines        4379     4390      +11     
  Branches      737      740       +3     
==========================================
+ Hits         3754     3776      +22     
+ Misses        449      436      -13     
- Partials      176      178       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jstasiak
Copy link
Contributor

Thank you for this. FWIW as I mentioned in #123 (comment) I'm currently undecided on this feature.

@claytonsingh
Copy link
Contributor Author

claytonsingh commented Feb 20, 2024

Flags in python never quite felt right to me either. I tried to be as consistant with the existing codebase as possible, such as the IPAddress constructor.

Otherwise I could reimpliment this with a tuple flags, seperate parameter, a class method, or some other way if you have any ideas. A few interface examples:

nwk = IPNetwork('192.168.0.1/24', flags=NOHOST | HOSTMASK)
nwk = IPNetwork('192.168.0.1/24', flags=(NOHOST, HOSTMASK))
nwk = IPNetwork('192.168.0.1/24', nohost=True, hostmask=True)

If you feel this is a bad fit I understand you closing the MR.

@jstasiak
Copy link
Contributor

To clarify, I'm hesitant regarding the feature itself (supporting ACL masks) – the way to trigger the feature is secondary, although I share your thoughts about integer flags here.

@claytonsingh
Copy link
Contributor Author

Unfortunately cisco did decide to use acl masks, so they are out there and likely never going away. I am currently splitting off the ACL masks then applying a hack before passing it to the IPNetwork constructor. Its works but is kind of a pain.

Could you provide more detail as to why you are hesitant regarding the feature itself?

@jstasiak
Copy link
Contributor

I'm just unsure if the benefit is worth the increased interface complexity cost. Maybe this is used/needed more commonly then I think though.

@jstasiak
Copy link
Contributor

Interface-wise I think something like

nwk = IPNetwork('192.168.0.1/24', nohost=True, hostmask=True)

(nohost and hostmask keyword-only, names to be adjusted as needed)

would be better than the current flag system.

@claytonsingh
Copy link
Contributor Author

claytonsingh commented Feb 20, 2024

If that is the case then I can (with your approval)

  • Make a new MR to add keyword flags to all classes
    • Update the documentation and mark the flags field a deprecated
  • Update this MR to do the same (removing the HOSTMASK constant)

@jstasiak
Copy link
Contributor

I think let's hold on on changing the existing flags – I need to think about this some more.

This PR though – please change the flag to a keyword-only parameter.

One note – we definitely need a doctest in IPNetwork to show how the parameter affects parsing (and maybe mention Cisco and ACLs too).

Thank you.

@claytonsingh
Copy link
Contributor Author

claytonsingh commented Feb 23, 2024

I am going to have to strongly disagree here. I think it would be a really bad idea to split the API and have some flags and some keyword-only parameters. There should be one clear consistant way to call the methods.

Edit: There is already a doctest using flags. I could add a note about Cisco and ACLs.
https://github.com/netaddr/netaddr/pull/376/files#diff-a89567e4b1edf284bb7d536df42bfc0d6ac51b2ac9b86cd3bca746169aab4b82R999-R1002

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 this pull request may close these issues.

IPNetwork constructor should add a parameter to indicate whether the input mask is an acl mask
3 participants