Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix warnings: classic int division & unclosed file #16

Merged
merged 2 commits into from

2 participants

@miso-belica

Hi,
there are some annoying warnings if I import charade in my project.

DeprecationWarning: classic int division

When I run tests for charade I get some extra warnings.

test.py:28: ResourceWarning: unclosed file <_io.BufferedReader name='...'>
  for line in open(self.file_name, 'rb'):

I use commands bellow to run python script:

python -tt -Wall -3 test.py
python3 -tt -Wall test.py
@sigmavirus24 sigmavirus24 merged commit 8fb0304 into from
@sigmavirus24

Sorry this took so long. Thank you so much for it! :cake:

@miso-belica miso-belica deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2013
  1. @miso-belica
Commits on Mar 20, 2013
  1. @miso-belica

    Close open test files

    miso-belica authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 6 deletions.
  1. +1 −1  charade/jpcntx.py
  2. +1 −1  charade/latin1prober.py
  3. +6 −4 test.py
View
2  charade/jpcntx.py
@@ -169,7 +169,7 @@ def got_enough_data(self):
def get_confidence(self):
# This is just one way to calculate confidence. It works well for me.
if self._mTotalRel > MINIMUM_DATA_THRESHOLD:
- return (self._mTotalRel - self._mRelSample[0]) / self._mTotalRel
+ return float(self._mTotalRel - self._mRelSample[0]) / self._mTotalRel
else:
return DONT_KNOW
View
2  charade/latin1prober.py
@@ -129,7 +129,7 @@ def get_confidence(self):
if total < 0.01:
confidence = 0.0
else:
- confidence = ((self._mFreqCounter[3] / total)
+ confidence = ((float(self._mFreqCounter[3]) / total)
- (self._mFreqCounter[1] * 20.0 / total))
if confidence < 0.0:
confidence = 0.0
View
10 test.py
@@ -25,11 +25,13 @@ def __init__(self, file_name, encoding):
def runTest(self):
u = UniversalDetector()
- for line in open(self.file_name, 'rb'):
- u.feed(line)
- if u.done:
- break
+ with open(self.file_name, 'rb') as file:
+ for line in file:
+ u.feed(line)
+ if u.done:
+ break
u.close()
+
self.assertEqual(u.result['encoding'].lower(), self.encoding,
"Expected %s, but got %r in %s" %
(self.encoding, u.result['encoding'],
Something went wrong with that request. Please try again.