Python Forum
completed module: validip.py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
completed module: validip.py
#4
(Dec-27-2016, 10:22 AM)wavic Wrote: it'll be nice if the function's doc string were more than just copy/paste of the function name. What the function is doing for example

yeah, i do want to add more documentation.  this was a two hour project, so far.

(Dec-27-2016, 11:34 PM)micseydel Wrote: On top of wavic's comment, this requires internet access, right? The naming here, to me at least, implies that 8.8.8.8 should be considered valid with or without internet access. Exceptions seem like a weird methodology here, so false negatives seem possible in other situations as well (I haven't dug through the docs to see what exactly). It also means that with a shaky internet connection or something, you'll get inconsistent return values if you call this frequently, which would be surprising to a caller expecting idempotence. Lastly, in a loop, this will be much slower than non-IO means of similar checking. The scope in which this is meant to be used should definitely be documented at least. For some precedent if you think this isn't a big deal: http://brian.pontarelli.com/2006/12/05/m...uals-suck/

Code like
def validip(addr):
   if validipv4(addr):
       return True
   if validipv6(addr):
       return True
   return False
can be written more succinctly
def validip(addr):
   return validipv4(addr) or validipv6(addr)
(generally, logic around returning Booleans can be simplified like this)

Both functions validipv* have similar bodies and can be refactored for DRYer code. You can save a line by returning right away too.

The 4+6 thing is bizarre; why not just use flags?

The return codes are bizarre as well, and not documented in the script. Since positive values indicate the count of failed IPs, and that *could* collide with the 98 value, you can use negative values one way or the other.

How can you hit the branch on line 97? You catch the IOErrors at lower levels, right? Similarly, for line 102, the return value is always an int, so that should not happen either, right?

You have an unused import, I recommend you use a linter.

that (return validipv4(addr) or validipv6(addr)) does look like better code.  i guess i'm still not well weened off C.  i need to work on that.

the 4+6 thing is the result of fast evolution and not yet refactoring anything.  and a bit of old C or old assembly thinking.

the "mains" code was an insert from a template file. i need to review and refactor the whole thing in it's own context.  i like doing that after getting some feedback.

the except at line 97 was there first as part of the initial construct before writing the code. it handles cases commonly seen in unix commands.  when i begin writing modules and commands i start by making a copy of a template for my initial construct.  maybe the template needs some improvement?

i forgot to take version out.  the template has sample code that uses version, which i removed, so i should have been more thorough.  what linter do you suggest and why?  pylint?  pyflakes?  i'd prefer one that is 100% python (3) so i can add stuff to it.  yeah, i'd probably ruin it, but that's the fun of open source.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
completed module: validip.py - by Skaperen - Dec-27-2016, 10:14 AM
RE: completed module: validip.py - by wavic - Dec-27-2016, 10:22 AM
RE: completed module: validip.py - by Skaperen - Dec-28-2016, 01:58 AM
RE: completed module: validip.py - by Skaperen - Jan-04-2017, 06:39 AM
RE: completed module: validip.py - by micseydel - Dec-27-2016, 11:34 PM
updated code: validip.py - by Skaperen - Dec-28-2016, 05:45 AM
RE: completed module: validip.py - by wavic - Dec-28-2016, 07:02 AM
RE: completed module: validip.py - by Skaperen - Dec-28-2016, 09:53 AM
RE: completed module: validip.py - by micseydel - Jan-02-2017, 05:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Tic Tac Toe With Enhanced Features - Completed adt 2 2,980 Dec-10-2019, 06:22 AM
Last Post: adt
  my earliest completed script Skaperen 0 2,029 Mar-08-2019, 09:50 PM
Last Post: Skaperen
  [link]Creating-a-repo-for-your-completed-scripts metulburr 0 7,656 Aug-29-2018, 01:19 PM
Last Post: metulburr
  Criticism on one of my first completed programs in Python Zombie_Programming 5 4,065 Jul-12-2018, 07:11 AM
Last Post: Zombie_Programming

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020