Skip to content

Conversation

@echoix
Copy link
Member

@echoix echoix commented Apr 20, 2025

There was another ResourceWarning error in manual generation that I solved after #5560. The unclosed files were defined in the argparse arguments with FileType type.

The argparse FileType argument type will be deprecated in Python 3.14. It does not properly close files if a subsequent error in another FileType argument occurs when parsing. The suggestion is to use context managers after parsing the arguments. The implementation of the changes is inspired by a PR doing the same in the CPython repo.

Other small changes included in (wasn't worth a separate PR):

  • Removing urlopen()'s proxies argument. It was for the old interface. Default proxy handling is used now. It allowed correct type checking.
  • Invalid None assignment to nothing in res.append(line) if res is not None else None, replaced with elif res is not None: and res.append(line), as intended 10+ years ago.
  • Initialized optname variable in function split_in_groups if ever the first condition wasn't executed for a previous line (for type checking, as it was unbounded otherwise)
  • Renamed variable of argument destination with typo from htmlparmas to htmlparams (two occurrences only, used once)
  • Added a note to an append operation where type checking clearly indicates an error, but changes would be out of scope here.
  • Collapsed a if line.startswith("/*"): continue that was not required because of the condition above, that already checked for this situation just above.

Type checking was added to touched/impacted functions to validate correct usages.

echoix added 4 commits April 20, 2025 17:07
The argparse FileType argument type will be deprecated in Python 3.14. It does not properly close files if a subsequent error in another FileType argument occurs when parsing. The suggestion is to use context managers after parsing the arguments. The implementation of the changes is inspired by a PR doing the same in the CPython repo.
@github-actions github-actions bot added Python Related code is in Python docs labels Apr 20, 2025
@echoix echoix requested a review from petrasovaa May 14, 2025 18:53
@echoix echoix merged commit 7e69717 into OSGeo:main May 15, 2025
28 checks passed
@echoix echoix deleted the parser-standard-options-filetype branch May 15, 2025 15:44
@github-actions github-actions bot added this to the 8.5.0 milestone May 15, 2025
wenzeslaus pushed a commit that referenced this pull request Jul 15, 2025
We don't have any use for using URL as a parameter in the script which generates documentation for standard options for the parser.
 
Follow up from #5561

Closes #5654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants