Ticket #198 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

a lot of equations like type(x) == type("")

Reported by: getxsick Owned by: boltrix
Priority: low Milestone:
Component: Umit Version: current svn
Keywords: Cc: gpolo

Description

there are thousands of them in umit code. even better is type(x) is object (e.g. type(x) is str but perhaps better is to use isinstance() than checking about.

another issue is that type checking in general meaning about bad style ;)

Attachments

instance_checking.diff (8.7 kB) - added by getxsick 4 years ago.
removing StringTypes? and type(X()) style

Change History

  Changed 4 years ago by gpolo

The idiom "type(x) is str" is actually worse than "type(x) == type()" and equivalents because you can shadow the str type by an arbitrary object. And it is very likely that you want/need to check against both str and unicode in several places in umit (but this is not really related to this ticket).

I prefer isinstance over type calls, specially because there is this umitplugins now.

Finally, as your last phrase says, it is very possible that several of these checks should go in order to not hide other bugs (I noticed most of them could go in the NmapParser?, but didn't remove yet).

  Changed 4 years ago by gpolo

trac ate my second example:

type(x) == type('')

  Changed 4 years ago by getxsick

so are we going to do anything with this issue or leave as it is?

  Changed 4 years ago by gpolo

Each case, or a group of them, need to be evaluated separately. If you have any patches over there, just attach them here.

  Changed 4 years ago by gpolo

  • milestone Umit 1.0beta1 deleted

  Changed 4 years ago by gpolo

  • type changed from defect to enhancement

  Changed 4 years ago by gpolo

  • priority changed from high to low

  Changed 4 years ago by getxsick

I attached a patch which replace all type checking in whole umit by instance checking. Propably some works are still needed for avoid useless checkings anyway.

  Changed 4 years ago by nopper

Replace isinstance(object, str) with isinstance(object, basestring) and then you could commit to trunk imho.

  Changed 4 years ago by getxsick

updated. i'm waiting for gpolo vote, cause he was active in this ticket...

follow-ups: ↓ 12 ↓ 13   Changed 4 years ago by gpolo

That is very far from being a patch that "replaces all type checking in while umit by instance checking", getxsick. umit/gui/SearchGUI has several other cases, as does umit/gui/OptionBuilder

Also, what are we gaining by blindly changing type calls to isinstane calls ? Take this function "switch_host_details" in umit/gui/ScanNotebook, why does it have to do such type check ? It would be way better if type checks were eliminated, instead of just replaced by isinstance calls. Apparently I wasn't clear enough when I said the cases needed to be evaluated.

in reply to: ↑ 11   Changed 4 years ago by getxsick

Replying to gpolo:

That is very far from being a patch that "replaces all type checking in while umit by instance checking", getxsick. umit/gui/SearchGUI has several other cases, as does umit/gui/OptionBuilder

ok, i made it to fast and forgot about those where just create new instance i'm attaching a new patch, also i removed deprecated StringTypes?

Also, what are we gaining by blindly changing type calls to isinstane calls ? Take this function "switch_host_details" in umit/gui/ScanNotebook, why does it have to do such type check ? It would be way better if type checks were eliminated, instead of just replaced by isinstance calls. Apparently I wasn't clear enough when I said the cases needed to be evaluated.

isn't the same what i said when i created a ticket and in the comment when attached the file?

Propably some works are still needed for avoid useless checkings anyway.

So yes, it doesn't mean that I'm going to close this ticket. It's just a some simple (or blindly if you would preffer) changing, which are make code even better than before, but some other works (which we both pointed) should be done too.

Changed 4 years ago by getxsick

removing StringTypes? and type(X()) style

in reply to: ↑ 11   Changed 4 years ago by getxsick

Replying to gpolo:

Also, what are we gaining by blindly changing type calls to isinstane calls ?

I thought that i included answer for this in your second question but for clarify.

We are just making it in proper way, which is officialy recommended by Python Software Foundation. So it's some good point for the beginning, and next evolution should be done.

  Changed 3 years ago by ignotus

I think getxsick can apply the patch (or an updated version of it, since is a year old patch) and open another ticket for the remaining "problems".

  Changed 3 years ago by getxsick

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.