Skip to content

Conversation

micahcochran
Copy link
Contributor

Closes files bdatfile and bdatmetafile in the _readboundarydata function.

This solves warnings like these on Python 3.x:

/.../lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py:1087: ResourceWarning: unclosed file <_io.TextIOWrapper name='/.../lib/python3.4/site-packages/mpl_toolkits/basemap/data/gshhsmeta_c.dat' mode='r' encoding='UTF-8'>
  self._readboundarydata('gshhs',as_polygons=True)
/.../python3.4/site-packages/mpl_toolkits/basemap/__init__.py:1095: ResourceWarning: unclosed file <_io.BufferedReader name='/.../lib/python3.4/site-packages/mpl_toolkits/basemap/data/gshhs_c.dat'>
  self._readboundarydata('gshhs',as_polygons=False)

This seems to be the simplest way to accomplish this. ResourceWarnings are most of the warning raised when running test.py on Python 3.x.

Closes files bdatfile and bdatmetafile.  This seems to be the simplest way to accomplish this.

This solves warnings like this:
```
/.../lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py:1087: ResourceWarning: unclosed file <_io.TextIOWrapper name='/.../lib/python3.4/site-packages/mpl_toolkits/basemap/data/gshhsmeta_c.dat' mode='r' encoding='UTF-8'>
  self._readboundarydata('gshhs',as_polygons=True)
/.../python3.4/site-packages/mpl_toolkits/basemap/__init__.py:1095: ResourceWarning: unclosed file <_io.BufferedReader name='/.../lib/python3.4/site-packages/mpl_toolkits/basemap/data/gshhs_c.dat'>
  self._readboundarydata('gshhs',as_polygons=False)
```

ResourceWarnings are most of the warning raised when running test.py.
@WeatherGod
Copy link
Member

I was about to suggest to use with-statements instead, but then I noticed which method this was in. I wouldn't want to clutter our diff history just to indent that ungodly chunk of code.

One day, I'll rework that sucker. Even if it is just simply to say "I tackled that beast...". We will see what the output looks like shortly.

@WeatherGod
Copy link
Member

Much better! Now it looks like we have to deal with the non-integer indexing issue. I am sure there are much more instances of it than the warnings are now showing, though.

Merging!

WeatherGod added a commit that referenced this pull request Dec 16, 2015
stops ResourceWarnings for unclosed files
@WeatherGod WeatherGod merged commit f8252e5 into matplotlib:master Dec 16, 2015
@micahcochran
Copy link
Contributor Author

Thank you.

@micahcochran micahcochran deleted the stop-resource-warnings branch December 16, 2015 19:24
@QuLogic
Copy link
Member

QuLogic commented Dec 16, 2015

Since the file open/close is basically around the entire function, the easiest way to avoid all that indent is to rename the function to something like _readboundarydatafromfile and have it take those two files as parameters, then create a new _readboundarydata that just opens the file in a with statement and only calls the renamed function.

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.

3 participants